Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Trace ID #1531

Closed
jam0cam opened this issue Aug 11, 2020 · 17 comments
Closed

Duplicate Trace ID #1531

jam0cam opened this issue Aug 11, 2020 · 17 comments
Labels
Bug Something isn't working release:after-ga

Comments

@jam0cam
Copy link

jam0cam commented Aug 11, 2020

Describe the bug
In traces where the same name is used, I sometimes get the same trace id. This happens over different app launches. See the screenshots, some duplication is almost an hour apart.

Steps to reproduce
Normal usage should produce this. I have about 15-20 unique traces throughout my app, and I would see duplicates among some of those traces.

What version and what artifacts are you using?
io.opentelemetry:opentelemetry-sdk:0.7.0
io.opentelemetry:opentelemetry-exporters-zipkin:0.6.0

Environment
Android emulator, API 28

Additional context
on a basic level, this how the trace is done:

val span = tracer.spanBuilder(name.value).startSpan()
...
span.end()

Screenshots from honeycomb
image

@jam0cam jam0cam added the Bug Something isn't working label Aug 11, 2020
@Oberon00
Copy link
Member

I don't think this has anything to do with the name. Probably the seed or algorithm of the RNG is bad.

@jkwatson
Copy link
Contributor

We're using ThreadLocalRandom for the id generation, by default. Is Android's implementation of TLR bad? You might need to replace the IdGenerator implementation for Android, perhaps?

@jkwatson
Copy link
Contributor

@jam0cam can you solve your issue here by implementing a custom IdGenerator?

@jam0cam
Copy link
Author

jam0cam commented Aug 26, 2020

I was, thanks for the suggestion

@jkwatson
Copy link
Contributor

I was, thanks for the suggestion

good to hear! closing this issue.

@sumitm-iiit
Copy link

@jam0cam : What custom IdGenerator did you use ? Is it possible for you to share that ?

@jkwatson
Copy link
Contributor

@jam0cam : What custom IdGenerator did you use ? Is it possible for you to share that ?

More recent versions of the SDK will detect if you're on Android and fall back to one that works. You shouldn't need to use a custom id generator any more.

@sumitm-iiit
Copy link

@jkwatson : Do you know from which version of SDK this issue is fixed ?

@jkwatson
Copy link
Contributor

@jkwatson : Do you know from which version of SDK this issue is fixed ?

https://github.com/open-telemetry/opentelemetry-java/releases/tag/v1.2.0

@yadavraju
Copy link

yadavraju commented Feb 18, 2022

@jkwatson I am still seeing the same duplicate trace id in android in v 1.11.0

Screen Shot 2022-02-17 at 7 33 20 PM

@jkwatson
Copy link
Contributor

jkwatson commented Feb 18, 2022

Can you show how you're configuring your SDK?

@yadavraju
Copy link

yadavraju commented Feb 18, 2022

Screen Shot 2022-02-17 at 8 10 25 PM

I have created a singleton class in kotlin for SDK configuration in android @jkwatson

@jkwatson
Copy link
Contributor

Nothing looks amiss there to me. At Splunk, we're using OTel in our Android instrumentation and it's working 100% fine. I wonder if there's something odd you're doing with the Context that is keeping a span around as a parent in the Context that you aren't expecting.

Could you put together a simple sample application that reproduces the issue you're seeing?

Here's the Splunk repository, which includes a sample app that does work (and you can point it at zipkin, or just look at the output of debug logs to prove it): https://github.com/signalfx/splunk-otel-android

@yadavraju
Copy link

Here is a sample app repo: https://github.com/yadavraju/DisneyCodeChallenge

could you please have a look? I am totally new to opentelimetry

@jkwatson
Copy link
Contributor

Here is a sample app repo: https://github.com/yadavraju/DisneyCodeChallenge

could you please have a look? I am totally new to opentelimetry

It looks like you're holding onto spans for the lifetime of each activity and re-using as the parent of other spans over and over. Each of those spans will have the same trace id, because the parent span is constant and has that trace id.

You can't re-use parents like that, unless you want them to all be part of the same trace.

@yadavraju
Copy link

yadavraju commented Feb 19, 2022

@jkwatson I tried to use Splunk library code. How can I add child span in my view model class when adding all the space added to single traces. similar to this image

It happens when I open the same activity multiple times from the previous activity by going back and coming again.

I want to create different traces every time I open an activity (it's adding to the same traced: there is now 59 traces in images)

Screen Shot 2022-02-18 at 8 38 27 PM

fun fetchFlightData() {
    viewModelScope.launch {
        val span = otel.startWorkflow("fetchFlightData:http:request")
        try {
            span.makeCurrent().use {
                span.addEvent("Loading api data")
                loadingObservableField.set(true)
                repository.getFlightData(OtelConfiguration.injectSpanContext())
                    .catch { e ->
                        handleException(TAG, e, loadingObservableField)
                        val attributes = Attributes.of(
                            AttributeKey.stringKey(StatusCode.ERROR.name),
                            "/@GET/flight"
                        )
                        span.recordException(e, attributes)
                    }
                    .collect {
                        displayFlightData.value = it
                        loadingObservableField.set(false)
                        span.addEvent("Api data loaded: $it")
                    }
            }
        } finally {
            span.end()
        }
    }
}

@jkwatson
Copy link
Contributor

@jam0cam I recommend learning how the OpenTelemetry tracing system works, using something simple like a main method and a couple of threads. Writing instrumentation for Android is not trivial, due to needing to have a deep understanding of the threading model, and how that will interact with the OpenTelemetry Context propagation mechanisms.

This is definitely not the forum to try to debug something as complex as you're trying to do. You will probably need to dig deep and debug what's happening in your case, once you have a strong understanding of how OTel works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working release:after-ga
Projects
None yet
Development

No branches or pull requests

5 participants