microsoft / microsoft/ApplicationInsights-JS
trackDependencyData id format validation breaks W3C correlation with plain spanId
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 685
- Forks
- 261
- Avg merge
- 21h 33m
- Merged PRs (30d)
- 5
Description
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](https://github.com/microsoft/ApplicationInsights-JS/blob/c3d37b89aeffdcf397d7edb02e10579c9770263a/extensions/applicationinsights-dependencies-js/src/ajax.ts#L531C21-L539C22)**
```javascript
// 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:
```javascript
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)
- `861bce51737e3ba6` → `861bce51737e3ba6` (plain spanId, leave alone)
## Reproduction
```javascript
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
- PR #1213 introduced this behavior
- Issue #1136 discussed ID format changes
Contributor 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.
Research direction
Start in extensions/applicationinsights-dependencies-js/src/ajax.ts around lines 531-539 and trace the trackDependencyData handling for dependency.id. Reproduce the W3C case with the plain spanId and compare it with the legacy |traceId.spanId form. Done means legacy IDs receive the required trailing period while plain spanIds remain unchanged and correlation is preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100