Skip to content

Attach custom child spans to the cold app start transaction  #3581

Description

@zhukic

Problem Statement

Hi!

I use the performance v2 feature, and as the next step, I'd like to measure specific operations time during the application.load operation, for example, and enrich the transaction with more detailed spans.
I haven't found the proper way to do this at the moment.
Could you please suggest if there is some workaround to do that using the current API(custom callbacks or event processor?)

Expected behaviour: possibility to add child spans to the existing spans(application.load, activity.load, etc.) during cold app start.

SDK version - 7.9.0

Thank you!

Solution Brainstorm

No response

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 16, 2024
  2. zhukic commented on Jul 16, 2024

    @zhukic
    Author

    I also have some "Missing instrumentation" spans. I know which operations causes them and I'd like to have possibility to mark them explicitly as the child spans.

    image

  3. markushi commented on Jul 17, 2024

    @markushi
    Member

    @zhukic thanks for reaching out! Yes, that's something we've been considering for a while, let me discuss this internally!

    In the meantime you could utilize EventProcessors to add your custom spans, here's a snippet:
    Beware these are internal APIs, so they might not be stable across releases.

    SentryAndroid.init(this) { options ->
                options.apply {
                    dsn = ...
                    addEventProcessor(object : EventProcessor {
                        @Suppress("UnstableApiUsage")
                        override fun process(
                            transaction: SentryTransaction,
                            hint: Hint
                        ): SentryTransaction {
                            transaction.contexts.trace?.traceId?.let { traceId ->
                                transaction.spans
                                    .firstOrNull { it?.op.equals("app.start.cold") }
                                    ?.let { appStartSpan ->
                                        val parentSpanId = appStartSpan.spanId
    
                                        val startTimeStamp = 0.0 // unix time in seconds
                                        val endTimeStamp = 0.0 // unix time in seconds
                                        val op = "component.op"
                                        val description = "description"
    
                                        transaction.spans.add(
                                            SentrySpan(
                                                startTimeStamp,
                                                endTimeStamp,
                                                traceId,
                                                SpanId(),
                                                parentSpanId,
                                                op,
                                                description,
                                                SpanStatus.OK,
                                                null,
                                                emptyMap(),
                                                emptyMap(),
                                                emptyMap(),
                                                emptyMap(),
                                            )
                                        )
                                    }
                            }
                            return transaction
                        }
                    })
                }
            }
  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 17, 2024
  5. markushi commented on Jul 17, 2024

    @markushi
    Member

    @zhukic could you describe your use-case a bit more in detail? Which kind of operations do you want to measure? Is it mainly about the execution of Application.onCreate()?

  6. self-assigned this
    on Jul 17, 2024
  7. zhukic commented on Jul 18, 2024

    @zhukic
    Author

    @markushi Thank you for the answers!

    I'll try the approach with the EventProcessor a bit later.

    could you describe your use-case a bit more in detail? Which kind of operations do you want to measure? Is it mainly about the execution of Application.onCreate()?

    During the Application.onCreate() I initialize lots of my app's components and it takes some time. I'd like to have a possibility to measure all the initializations separately and attach them as the child spans to the application.load span.

    The second use case is described here. It's my code which runs on the UI thread, and currently, it's marked as "Missing instrumentation". I'd also like to have a possibility to attach it as a child span. I guess, this can be also solved by a custom EventProcessor.

  8. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 18, 2024
  9. romtsn commented on Jul 18, 2024

    @romtsn
    Contributor

    @zhukic thanks for the details, that's very helpful! On a side note - would you be interested if we provided auto-instrumentation for those components that get initialized as part of Application.onCreate? We have some ideas on how to to do that, although it may become a bit noisy, but we can think of some configuration/ignorelist.

  10. 7 remaining items

  11. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 22, 2024
  12. markushi commented on Jul 29, 2024

    @markushi
    Member

    @zhukic Glad it's working for you! Actually it should be safer to use BeforeSendTransactionCallback instead of a custom EventProcessor, as the BeforeSendTransactionCallback is executed after all processors.

  13. removed their assignment
    on Apr 7, 2025
  14. linear-code commented on Apr 2, 2026

    @linear-code

    Internal reference: JAVA-359

  15. buenaflor commented on Jul 7, 2026

    @buenaflor
    Contributor

    Supported in the next released version using the new extend app start API (only enabled in combination with options.enableStandaloneAppStartTracing) See: #5604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions