Skip to content

trackDependencyData id format validation breaks W3C correlation with plain spanId #2686

@szelpe

Description

@szelpe

When using trackDependencyData with W3C distributed tracing mode, the SDK blindly appends a trailing period to any id that doesn't already end with one. This breaks correlation when passing a plain W3C spanId.

Current behavior ajax.ts

// Hack since expected format in w3c mode is |abc.def.
// Non-w3c format is |abc.def
// @todo Remove if better solution is available, e.g. handle in portal
if (dependency.id[dependency.id.length - 1] !== ".") {
    dependency.id += ".";
}

The code only checks if the last character is a period, not whether the ID is actually in the expected |{traceId}.{spanId} format.

Problem

When manually tracking dependencies with trackDependencyData using a plain W3C spanId:

  • Input: id: "861bce51737e3ba6" (16-char hex spanId)
  • Result: "861bce51737e3ba6." (spanId with trailing period)

This doesn't match the server-side parent_id (which is the plain spanId from the W3C traceparent header), breaking parent-child correlation in the waterfall view.

Expected behavior

The SDK should only append a period if the ID matches the legacy |{traceId}.{spanId} format:

const legacyIdPattern = /^\|[a-f0-9]+\.[a-f0-9]+$/i;
if (legacyIdPattern.test(dependency.id)) {
    dependency.id += ".";
}

This would:

  • |abc123.def456|abc123.def456. (legacy format, add period)
  • 861bce51737e3ba6861bce51737e3ba6 (plain spanId, leave alone)

Reproduction

appInsights.trackDependencyData({
    id: "861bce51737e3ba6", // plain W3C spanId
    name: "GET /api/user",
    duration: 100,
    success: true,
    responseCode: 200,
    type: "HTTP",
    target: "api.example.com"
});
// Results in id: "861bce51737e3ba6." which doesn't correlate with server parent_id

Environment

  • SDK version: latest
  • distributedTracingMode: W3C

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions