Skip to content

Commit d6e7fe7

Browse files
authored
fix: http.response_content_length does not get populated when ignoreNetworkEvents is set to true (#2880)
1 parent f8ffeb0 commit d6e7fe7

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

plugins/web/opentelemetry-instrumentation-document-load/src/instrumentation.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ export class DocumentLoadInstrumentation extends InstrumentationBase<DocumentLoa
117117
if (fetchSpan) {
118118
fetchSpan.setAttribute(SEMATTRS_HTTP_URL, location.href);
119119
context.with(trace.setSpan(context.active(), fetchSpan), () => {
120-
if (!this.getConfig().ignoreNetworkEvents) {
121-
addSpanNetworkEvents(fetchSpan, entries);
122-
}
120+
addSpanNetworkEvents(
121+
fetchSpan,
122+
entries,
123+
this.getConfig().ignoreNetworkEvents
124+
);
123125
this._addCustomAttributesOnSpan(
124126
fetchSpan,
125127
this.getConfig().applyCustomAttributesOnSpan?.documentFetch
@@ -205,9 +207,11 @@ export class DocumentLoadInstrumentation extends InstrumentationBase<DocumentLoa
205207
);
206208
if (span) {
207209
span.setAttribute(SEMATTRS_HTTP_URL, resource.name);
208-
if (!this.getConfig().ignoreNetworkEvents) {
209-
addSpanNetworkEvents(span, resource);
210-
}
210+
addSpanNetworkEvents(
211+
span,
212+
resource,
213+
this.getConfig().ignoreNetworkEvents
214+
);
211215
this._addCustomAttributesOnResourceSpan(
212216
span,
213217
resource,

plugins/web/opentelemetry-instrumentation-document-load/test/documentLoad.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,27 @@ describe('DocumentLoad Instrumentation', () => {
834834
done();
835835
});
836836
});
837+
838+
it('should have http.response_content_length attribute even if ignoreNetworkEvents is true', done => {
839+
plugin = new DocumentLoadInstrumentation({
840+
enabled: false,
841+
ignoreNetworkEvents: true,
842+
});
843+
plugin.enable();
844+
845+
setTimeout(() => {
846+
const spans = exporter.getFinishedSpans();
847+
const resourceSpan = spans.find(
848+
s => s.name === 'resourceFetch'
849+
) as ReadableSpan;
850+
assert.isOk(resourceSpan, 'resourceFetch span should exist');
851+
assert.exists(
852+
resourceSpan.attributes[SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH],
853+
'http.response_content_length attribute should exist'
854+
);
855+
done();
856+
});
857+
});
837858
});
838859
});
839860

0 commit comments

Comments
 (0)