Able to see traces with Java, but no trace with Scala (same code)
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Domain
- observability, stream-processing
Research direction
Start with the Issue.call entry point and compare the Java and Scala snippets, including the trace-parent values, span setup, and exporter configuration. Reproduce with OpenTelemetry 1.49.0 and verify whether the Scala path exports a span that appears in the listed tracing back ends; done means the Scala streaming path produces a visible trace.
Written by the indexing model from the issue text.
Description
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!
- Dominant language
- Java
- Stars
- 2.5k
- Forks
- 1.1k
- Avg merge
- 5d 11h
- Merged PRs (30d)
- 41
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from open-telemetry/opentelemetry-java
-
`B3PropagatorExtractorMultipleHeaders` allocates when headers are missingPossibly taken @Eliot5566 claimed this today. OpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
open-telemetry/opentelemetry-java#9065 ·
Maintainers usually reply within 3 days
-
[incubator] ComposableProbabilitySampler does not validate ratio rangePossibly taken @eminfikret claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
open-telemetry/opentelemetry-java#9046 · 2 comments · 1 assignee ·
Maintainers usually reply within 3 days
-
PrometheusComponentProvider promotes all resource attributes when resource_constant_labels is empty ({})Possibly taken @rooks-ns claimed this 19 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
open-telemetry/opentelemetry-java#9014 · 1 comment ·
Maintainers usually reply within 3 days
-
Fix `otel.sdk.log.created` counting semanticsPossibly taken @anuraaga claimed this 112 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
open-telemetry/opentelemetry-java#8688 ·
Maintainers usually reply within 3 days
-
SdkSpanBuilder drops invalid parent TraceState when IdGenerator.generatesRandomTraceIds() is truePossibly taken @Eliot5566 claimed this today. OpenBug SDK
Difficulty 4/5 3-5 days Newbie friendliness 48/100
open-telemetry/opentelemetry-java#9062 · 1 comment ·
Maintainers usually reply within 3 days
All issues in open-telemetry/opentelemetry-java
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
micronaut-projects/micronaut-core#14585 ·
Maintainers usually reply within 1 day
-
Mend: dependency security vulnerability untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
opensearch-project/cross-cluster-replication#1805 ·
Maintainers usually reply within 1 day
-
feature request needs triage
Difficulty 1/5 Under an hour Newbie friendliness 66/100
TeamNewPipe/NewPipe#14083 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
PCL-Community/PCL-CE#3907 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 2 days