Able to see traces with Java, but no trace with Scala (same code)

Ouverte
#7,333 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 3 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
25/100
Type d'issue
Bug
Clarté
À clarifier
Activité
À l'abandon
Stack technique
java, kafka, scala, spark

Piste de recherche

Commencez par le point d’entrée Issue.call et comparez les extraits Java et Scala, notamment les valeurs de trace-parent, la configuration du span et la configuration de l’exporter. Reproduisez le problème avec OpenTelemetry 1.49.0 et vérifiez si le chemin Scala exporte un span qui apparaît dans les backends de tracing listés ; le travail est terminé lorsque le chemin de streaming Scala produit une trace visible.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Bug

Describe the bug
A clear and concise description of what the bug is.

=> I am able to send traces with below Java code, I can even see the traces in our tracing back-ends.

However, what seems to be the same code (can be discussed) in Scala will yield no trace at all.

Both are using the same OpenTelemetry API, SDK and exporter OTLP

Steps to reproduce
If possible, provide a recipe for reproducing the error.

Here is the java code.
I hope it is as minimal and as descriptive as possible.

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.*;
import io.opentelemetry.context.Context;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;

public class AAA {

    public String call(String traceParent) throws Exception {
        //String traceParent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"; //for testing

        OtlpGrpcSpanExporter spanExporter = OtlpGrpcSpanExporter.builder()
                .setEndpoint("https://tempo-prod-04-prod-us-east-0.grafana.net:443")
                .addHeader("Authorization", "Basic ODEwNzcxOmdsY19leUp2SWpvaU1[...]luQnliMlF0ZFhNdFpXRnpkQzB3SW4xOQ==")
                .build();
        Resource myResource = Resource.create(Attributes.of(AttributeKey.stringKey("service.name"), "javaservice"));
        SdkTracerProvider tracerProvider = SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(spanExporter)).build();
        OpenTelemetry openTelemetry = OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).build();
        String[] traceSplit = traceParent.split("-");
        SpanContext remoteContext = SpanContext.createFromRemoteParent(traceSplit[1], traceSplit[2], TraceFlags.getSampled(), TraceState.getDefault());
        Tracer tracer = openTelemetry.getTracer("from-java");
        SpanBuilder sb= tracer.spanBuilder("java-name").setSpanKind(SpanKind.CONSUMER);
        sb.setParent(Context.current().with(Span.wrap(remoteContext)));
        sb.setAttribute("testattributejava", "testattributejava");
        Span serverSpan = sb.startSpan();
        try {
            Thread.sleep(100); // mock our operation
            System.out.println("This is an example operation." + traceSplit[1] + traceSplit[2] + serverSpan + serverSpan.isRecording() + remoteContext);
            return serverSpan + " " + remoteContext;
        } finally {
            serverSpan.end();
        }
    }
    
}

And here is the Scala counterpart, not working.

import io.opentelemetry.api.common.Attributes
import io.opentelemetry.api.trace._
import io.opentelemetry.context.Context
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter
import io.opentelemetry.sdk.OpenTelemetrySdk
import io.opentelemetry.sdk.resources.Resource
import io.opentelemetry.sdk.trace.SdkTracerProvider
import io.opentelemetry.sdk.trace.`export`.SimpleSpanProcessor
import org.apache.spark.sql.Row

class Issue {

  def call(traceParent: (String, String)): String = {
    val spanExporter = OtlpGrpcSpanExporter.builder().setEndpoint("https://tempo-prod-04-prod-us-east-0.grafana.net:443").addHeader("Authorization", "Basic ODEwNzcxOmdsY19leUp2SWpvaU1UQTFOVFV4T1NJc0ltNGlPaUp6ZEdGamF5MDROVGcyTnpJdG[...]npkQzB3SW4xOQ==").build()
    val myResource = Resource.create(Attributes.builder().put("service.name", "scalaservice").build())
    val tracerProvider = SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(spanExporter)).build()
    val openTelemetry = OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).build()
    val remoteContext = SpanContext.createFromRemoteParent(traceParent._1, traceParent._2, TraceFlags.getSampled, TraceState.getDefault)
    val tracer = openTelemetry.getTracer("from-scala")
    val spanBuilder = tracer.spanBuilder("scala-name").setSpanKind(SpanKind.CONSUMER)
    spanBuilder.setParent(Context.current().`with`(Span.wrap(remoteContext)))
    spanBuilder.setAttribute("testAttributeScala1", "testAttributeScala2")
    val mySpan = spanBuilder.startSpan()
    try {
      Thread.sleep(400) //mock our work
      println(traceParent._1 + traceParent._2 + mySpan.toString + mySpan.isRecording + remoteContext)
      mySpan.toString
    } finally {
      mySpan.end()
    }
  }

What did you expect to see?
A clear and concise description of what you expected to see.

=> For both Java and Scala, I was hoping to see the trace in our tracing back ends. (Tested with Tempo, Lightstep, Datadog, Elastic APM)

What did you see instead?

=> We see the trace being sent for the Java code, but not for the Scala counterpart.

What version and what artifacts are you using?
Artifacts: => opentelemetry-api, opentelemetry-sdk, 1.49.0 which exporters => OTLP
Version: => 1.49.0
How did you reference these artifacts? (excerpt from your build.gradle, pom.xml, etc)

=> Here is the part from SBT

  "io.opentelemetry" % "opentelemetry-api" % "1.49.0",
  "io.opentelemetry" % "opentelemetry-sdk" % "1.49.0",
  "io.opentelemetry" % "opentelemetry-exporter-otlp" % "1.49.0",

Environment
Compiler: GraalVM 24, but we are not building native image
OS: The latest Noble

Additional context

Hello team,

This is my first issue in this repo.

If not anything else, just wanted to say thanks for the work.

Just wanted to reach out with a small issue.

We have a Java Spark Structured Streaming pipeline with kafka, where we would like to trace calls between Kafka producers (from different sources and languages) to our Spark job.

The above Java code is one step of the map reduce from Spark.

It is working. We can see traces in the different tracing backend.

However, a similar Spark Streaming job in Scala, with the similar map function (tracing) will not work.

No matter what, we cannot see the trace in any of the back end systems.

Could you please help on this issue?

Good day!

Langage dominant
Java
Étoiles
2.5k
Forks
1.1k
Merge moyen
5 j 11 h
PR mergées (30 j)
41

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de open-telemetry/opentelemetry-java

Toutes les issues de open-telemetry/opentelemetry-java

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.