From 4fcccaac8ab6825ac77510c0f86024e5a50f2ee7 Mon Sep 17 00:00:00 2001 From: David Kadlec Date: Fri, 17 Jan 2025 13:28:20 +0100 Subject: [PATCH 1/4] fix: add http.response.status_code --- .../src/tests/docload/docload.spec.ts | 7 ++++++- .../src/SplunkDocumentLoadInstrumentation.ts | 18 +++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/integration-tests/src/tests/docload/docload.spec.ts b/packages/integration-tests/src/tests/docload/docload.spec.ts index a07d8f4a..0c0bfeb3 100644 --- a/packages/integration-tests/src/tests/docload/docload.spec.ts +++ b/packages/integration-tests/src/tests/docload/docload.spec.ts @@ -50,7 +50,7 @@ test.describe('docload', () => { } }) - test('documentFetch, resourceFetch, and documentLoad spans', async ({ recordPage }) => { + test('documentFetch, resourceFetch, and documentLoad spans', async ({ recordPage, browserName }) => { await recordPage.goTo('/docload/docload.ejs') await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'documentLoad').length === 1) @@ -96,6 +96,11 @@ test.describe('docload', () => { expect(docFetchSpans[0].tags['link.traceId']).toBeDefined() expect(docFetchSpans[0].tags['link.spanId']).toBeDefined() + if (browserName !== 'webkit') { + // Webkit does not support https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus + expect(parseInt(docFetchSpans[0].tags['http.response.status_code'] as string)).toBeGreaterThan(0) + } + expect(parseInt(scriptFetchSpans[0].tags['http.response_content_length'] as string)).toBeGreaterThan(0) expect(docLoadSpans[0].tags['component']).toBe('document-load') diff --git a/packages/web/src/SplunkDocumentLoadInstrumentation.ts b/packages/web/src/SplunkDocumentLoadInstrumentation.ts index 39227708..ab6efaa8 100644 --- a/packages/web/src/SplunkDocumentLoadInstrumentation.ts +++ b/packages/web/src/SplunkDocumentLoadInstrumentation.ts @@ -17,7 +17,7 @@ */ import { InstrumentationConfig } from '@opentelemetry/instrumentation' -import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-document-load' +import { AttributeNames, DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-document-load' import * as api from '@opentelemetry/api' import { captureTraceParentFromPerformanceEntries } from './servertiming' import { PerformanceEntries } from '@opentelemetry/sdk-trace-web' @@ -65,27 +65,27 @@ export class SplunkDocumentLoadInstrumentation extends DocumentLoadInstrumentati span.setAttribute('component', this.component) } - if (span && exposedSpan.name !== 'documentLoad') { + if (span && exposedSpan.name !== AttributeNames.DOCUMENT_LOAD) { // only apply links to document/resource fetch // To maintain compatibility, getEntries copies out select items from // different versions of the performance API into its own structure for the // initial document load (but leaves the entries undisturbed for resource loads). - if ( - exposedSpan.name === 'documentFetch' && - !(entries as PerformanceEntriesWithServerTiming).serverTiming && - performance.getEntriesByType - ) { + if (exposedSpan.name === AttributeNames.DOCUMENT_FETCH && performance.getEntriesByType) { const navEntries = performance.getEntriesByType('navigation') - if (navEntries[0]?.serverTiming) { + if (!(entries as PerformanceEntriesWithServerTiming).serverTiming && navEntries[0]?.serverTiming) { ;(entries as PerformanceEntriesWithServerTiming).serverTiming = navEntries[0].serverTiming } + + if (navEntries[0]?.responseStatus) { + span.setAttribute('http.response.status_code', navEntries[0].responseStatus) + } } captureTraceParentFromPerformanceEntries(entries, span) span.setAttribute(SemanticAttributes.HTTP_METHOD, 'GET') } - if (span && exposedSpan.name === 'documentLoad') { + if (span && exposedSpan.name === AttributeNames.DOCUMENT_LOAD) { addExtraDocLoadTags(span) } From d1cbab505b482583406ac66b7642db4b9d66a0d0 Mon Sep 17 00:00:00 2001 From: David Kadlec Date: Fri, 17 Jan 2025 13:29:54 +0100 Subject: [PATCH 2/4] chore: ignore type --- packages/web/src/SplunkDocumentLoadInstrumentation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web/src/SplunkDocumentLoadInstrumentation.ts b/packages/web/src/SplunkDocumentLoadInstrumentation.ts index ab6efaa8..8b635e05 100644 --- a/packages/web/src/SplunkDocumentLoadInstrumentation.ts +++ b/packages/web/src/SplunkDocumentLoadInstrumentation.ts @@ -76,8 +76,8 @@ export class SplunkDocumentLoadInstrumentation extends DocumentLoadInstrumentati ;(entries as PerformanceEntriesWithServerTiming).serverTiming = navEntries[0].serverTiming } - if (navEntries[0]?.responseStatus) { - span.setAttribute('http.response.status_code', navEntries[0].responseStatus) + if ((navEntries[0] as any)?.responseStatus) { + span.setAttribute('http.response.status_code', (navEntries[0] as any).responseStatus) } } From 1a09d61ec107e4058fd09477e918a2aaf96c0121 Mon Sep 17 00:00:00 2001 From: David Kadlec Date: Fri, 17 Jan 2025 13:36:35 +0100 Subject: [PATCH 3/4] chore: upgrade TS, skipLibCheck --- package-lock.json | 9 +++++---- package.json | 2 +- packages/session-recorder/tsconfig.base.json | 3 ++- packages/web/src/SplunkDocumentLoadInstrumentation.ts | 4 ++-- packages/web/tsconfig.base.json | 3 ++- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 665b4a81..88fa0498 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "globals": "^15.11.0", "prettier": "^3.3.3", "size-limit": "^11.1.6", - "typescript": "^5.1.6", + "typescript": "^5.7.3", "typescript-eslint": "^8.12.2" }, "engines": { @@ -18005,10 +18005,11 @@ } }, "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", + "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", "dev": true, + "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index d8263b08..a9538e8a 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "globals": "^15.11.0", "prettier": "^3.3.3", "size-limit": "^11.1.6", - "typescript": "^5.1.6", + "typescript": "^5.7.3", "typescript-eslint": "^8.12.2" } } diff --git a/packages/session-recorder/tsconfig.base.json b/packages/session-recorder/tsconfig.base.json index 053cd98c..25ccd42e 100644 --- a/packages/session-recorder/tsconfig.base.json +++ b/packages/session-recorder/tsconfig.base.json @@ -8,7 +8,8 @@ "pretty": true, "resolveJsonModule": true, "target": "ES2017", - "types": ["node"] + "types": ["node"], + "skipLibCheck": true }, "include": ["src/**/*.ts", "src/**/*.js"], "exclude": ["node_modules"] diff --git a/packages/web/src/SplunkDocumentLoadInstrumentation.ts b/packages/web/src/SplunkDocumentLoadInstrumentation.ts index 8b635e05..ab6efaa8 100644 --- a/packages/web/src/SplunkDocumentLoadInstrumentation.ts +++ b/packages/web/src/SplunkDocumentLoadInstrumentation.ts @@ -76,8 +76,8 @@ export class SplunkDocumentLoadInstrumentation extends DocumentLoadInstrumentati ;(entries as PerformanceEntriesWithServerTiming).serverTiming = navEntries[0].serverTiming } - if ((navEntries[0] as any)?.responseStatus) { - span.setAttribute('http.response.status_code', (navEntries[0] as any).responseStatus) + if (navEntries[0]?.responseStatus) { + span.setAttribute('http.response.status_code', navEntries[0].responseStatus) } } diff --git a/packages/web/tsconfig.base.json b/packages/web/tsconfig.base.json index e529909b..acbd79cb 100644 --- a/packages/web/tsconfig.base.json +++ b/packages/web/tsconfig.base.json @@ -8,7 +8,8 @@ "pretty": true, "resolveJsonModule": true, "target": "ES2017", - "types": ["node"] + "types": ["node"], + "skipLibCheck": true }, "include": ["src/**/*.ts"], "exclude": ["node_modules"] From 3f3de13594f41dbf98047b4062e3c5044f53e796 Mon Sep 17 00:00:00 2001 From: Jozef Harag Date: Mon, 20 Jan 2025 09:48:34 +0100 Subject: [PATCH 4/4] chore: be precise in test --- packages/integration-tests/src/tests/docload/docload.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/integration-tests/src/tests/docload/docload.spec.ts b/packages/integration-tests/src/tests/docload/docload.spec.ts index 0c0bfeb3..f8f5f0ad 100644 --- a/packages/integration-tests/src/tests/docload/docload.spec.ts +++ b/packages/integration-tests/src/tests/docload/docload.spec.ts @@ -98,7 +98,7 @@ test.describe('docload', () => { expect(docFetchSpans[0].tags['link.spanId']).toBeDefined() if (browserName !== 'webkit') { // Webkit does not support https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus - expect(parseInt(docFetchSpans[0].tags['http.response.status_code'] as string)).toBeGreaterThan(0) + expect(parseInt(docFetchSpans[0].tags['http.response.status_code'] as string)).toBe(200) } expect(parseInt(scriptFetchSpans[0].tags['http.response_content_length'] as string)).toBeGreaterThan(0)