Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add 'http.response.status_code' to documentFetch span. #928

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion packages/session-recorder/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"pretty": true,
"resolveJsonModule": true,
"target": "ES2017",
"types": ["node"]
"types": ["node"],
"skipLibCheck": true
},
"include": ["src/**/*.ts", "src/**/*.js"],
"exclude": ["node_modules"]
Expand Down
18 changes: 9 additions & 9 deletions packages/web/src/SplunkDocumentLoadInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/web/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"pretty": true,
"resolveJsonModule": true,
"target": "ES2017",
"types": ["node"]
"types": ["node"],
"skipLibCheck": true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove this once we upgrade web-vitals package

},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
Expand Down
Loading