Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

How to start trace with custom trace-id and parent-id?

Open
#9,155 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
java, kafka

Research direction

Start with the Java entry points shown in the example—GlobalTracer.get(), buildSpan(...).asChildOf(), and CustomSpanContext—and compare how the stored Kafka headers are consumed in the outbox container. Determine what supported API, if any, accepts the trace-id and parent-id while preserving distributed tracing. Done means a span from publishFromOutbox appears in the existing trace with correlated logs.

Written by the indexing model from the issue text.

Description

type: feature request
Library Name

micronaut

Library Version(s)

dd-trace:1.50.1

Describe the feature you'd like

Hi,

We are storing outbox events for Kafka in the database with current span context headers:

headers={
x-datadog-parent-id=1425649086485655485,
x-datadog-sampling-priority=1,
tracestate=dd=s:1;
o:rum;
p:13c8ec4a6e566fbd,
x-datadog-origin=rum,
traceparent=00-000000000000000024fefac4c68ae928-13c8ec4a6e566fbd-01,
x-datadog-trace-id=2665843752501438760
}

and when these outbox events are picked (by a different container), we want to trace that operation but attach those spans to an already existing trace so that we can have support for:

  • distributed tracing
  • distributed logs
Is your feature request related to a problem?

No response

Describe alternatives you've considered

This is what we tried

  void publishFromOutbox(final Outbox outboxEvent) {
    final var tracer = GlobalTracer.get();
    final Span span = tracer.buildSpan(JOBS)
      .withTag(DDTags.RESOURCE_NAME, OUTBOX_SCHEDULER_PUBLISH)
      .ignoreActiveSpan()
      .asChildOf(new CustomSpanContext(
        outboxEvent.headers().get(X_DATADOG_TRACE_ID), outboxEvent.headers().get(X_DATADOG_PARENT_ID)))
      .start();
    tracer.activateSpan(span);
    publish(outboxEvent);
    tracer.activeSpan().finish();
  }

but we can see this doesn't work. Trace is not created or attached to any existing trace.

How can we accomplish starting trace with custom trace-id and parent-id? For PHP services we are using this handy method that you provide

    /**
     * Apply the distributed tracing information on the current and future spans. That API can be called if there is no
     * other currently active span.
     *
     * The distributed tracing context can be reset by calling 'set_distributed_tracing_context("0", "0")'
     *
     * @param string $traceId The unique integer (128-bit unsigned) ID of the trace containing this span
     * @param string $parentId The span integer ID of the parent span
     * @param string|null $origin The distributed tracing origin
     * @param array|string|null $propagated_tags If provided, propagated tags from the root span will be cleared and
     * replaced by the given tags and applied to existing spans
     * @return bool 'true' if the distributed tracing context was properly set, else 'false' if an error occurred
     */
    function set_distributed_tracing_context(
        string $traceId,
        string $parentId,
        ?string $origin = null,
        array|string|null $propagated_tags = null
    ): bool {}
Additional context

No response

Dominant language
Java
Stars
737
Forks
361
Avg merge
3d 20h
Merged PRs (30d)
173

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DataDog/dd-trace-java

All issues in DataDog/dd-trace-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.