Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

export enum PerformanceTimingNames {
CONNECT_END = 'connectEnd',
CONNECT_START = 'connectStart',
DECODED_BODY_SIZE = 'decodedBodySize',
DOM_COMPLETE = 'domComplete',
DOM_CONTENT_LOADED_EVENT_END = 'domContentLoadedEventEnd',
DOM_CONTENT_LOADED_EVENT_START = 'domContentLoadedEventStart',
DOM_INTERACTIVE = 'domInteractive',
DOMAIN_LOOKUP_END = 'domainLookupEnd',
DOMAIN_LOOKUP_START = 'domainLookupStart',
ENCODED_BODY_SIZE = 'encodedBodySize',
FETCH_START = 'fetchStart',
LOAD_EVENT_END = 'loadEventEnd',
LOAD_EVENT_START = 'loadEventStart',
NAVIGATION_START = 'navigationStart',
REDIRECT_END = 'redirectEnd',
REDIRECT_START = 'redirectStart',
REQUEST_START = 'requestStart',
RESPONSE_END = 'responseEnd',
RESPONSE_START = 'responseStart',
SECURE_CONNECTION_START = 'secureConnectionStart',
START_TIME = 'startTime',
UNLOAD_EVENT_END = 'unloadEventEnd',
UNLOAD_EVENT_START = 'unloadEventStart',
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
safeExecuteInTheMiddle,
} from '@opentelemetry/instrumentation';
import * as core from '@opentelemetry/core';
import * as web from '@opentelemetry/sdk-trace-web';
import { AttributeNames } from './enums/AttributeNames';
import { PerformanceTimingNames } from './enums/PerformanceTimingNames';
import {
ATTR_HTTP_STATUS_CODE,
ATTR_HTTP_HOST,
Expand All @@ -41,6 +41,13 @@ import {
ATTR_URL_FULL,
} from '@opentelemetry/semantic-conventions';
import type { FetchError, FetchResponse, SpanData } from './types';
import type { PropagateTraceHeaderCorsUrls } from './utils';
import {
addSpanNetworkEvents,
getResource,
parseUrl,
shouldPropagateTraceHeaders,
} from './utils';
import {
getFetchBodyLength,
normalizeHttpRequestMethod,
Expand Down Expand Up @@ -79,7 +86,7 @@ export interface FetchInstrumentationConfig extends InstrumentationConfig {
// is not available
clearTimingResources?: boolean;
// urls which should include trace headers when origin doesn't match
propagateTraceHeaderCorsUrls?: web.PropagateTraceHeaderCorsUrls;
propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls;
/**
* URLs that partially match any regex in ignoreUrls will not be traced.
* In addition, URLs that are _exact matches_ of strings in ignoreUrls will
Expand Down Expand Up @@ -141,23 +148,21 @@ export class FetchInstrumentation extends InstrumentationBase<FetchInstrumentati
const childSpan = this.tracer.startSpan(
'CORS Preflight',
{
startTime: corsPreFlightRequest[web.PerformanceTimingNames.FETCH_START],
startTime: corsPreFlightRequest[PerformanceTimingNames.FETCH_START],
},
trace.setSpan(context.active(), span)
);
const skipOldSemconvContentLengthAttrs = !(
this._semconvStability & SemconvStability.OLD
);
web.addSpanNetworkEvents(
addSpanNetworkEvents(
childSpan,
corsPreFlightRequest,
this.getConfig().ignoreNetworkEvents,
undefined,
skipOldSemconvContentLengthAttrs
);
childSpan.end(
corsPreFlightRequest[web.PerformanceTimingNames.RESPONSE_END]
);
childSpan.end(corsPreFlightRequest[PerformanceTimingNames.RESPONSE_END]);
}

/**
Expand All @@ -166,7 +171,7 @@ export class FetchInstrumentation extends InstrumentationBase<FetchInstrumentati
* @param response
*/
private _addFinalSpanAttributes(span: Span, response: FetchResponse): void {
const parsedUrl = web.parseUrl(response.url);
const parsedUrl = parseUrl(response.url);

if (this._semconvStability & SemconvStability.OLD) {
span.setAttribute(ATTR_HTTP_STATUS_CODE, response.status);
Expand Down Expand Up @@ -199,7 +204,7 @@ export class FetchInstrumentation extends InstrumentationBase<FetchInstrumentati
*/
private _addHeaders(options: Request | RequestInit, spanUrl: string): void {
if (
!web.shouldPropagateTraceHeaders(
!shouldPropagateTraceHeaders(
spanUrl,
this.getConfig().propagateTraceHeaderCorsUrls
)
Expand Down Expand Up @@ -310,7 +315,7 @@ export class FetchInstrumentation extends InstrumentationBase<FetchInstrumentati
'resource'
) as PerformanceResourceTiming[];
}
const resource = web.getResource(
const resource = getResource(
resourcesObserver.spanUrl,
resourcesObserver.startTime,
endTime,
Expand All @@ -331,7 +336,7 @@ export class FetchInstrumentation extends InstrumentationBase<FetchInstrumentati
const skipOldSemconvContentLengthAttrs = !(
this._semconvStability & SemconvStability.OLD
);
web.addSpanNetworkEvents(
addSpanNetworkEvents(
span,
mainRequest,
this.getConfig().ignoreNetworkEvents,
Expand Down Expand Up @@ -394,7 +399,7 @@ export class FetchInstrumentation extends InstrumentationBase<FetchInstrumentati
return original.apply(this, args);
}
const self = this;
const url = web.parseUrl(
const url = parseUrl(
args[0] instanceof Request ? args[0].url : String(args[0])
).href;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,15 @@ export const ATTR_HTTP_URL = 'http.url' as const;
* @deprecated Replaced by `user_agent.original`.
*/
export const ATTR_HTTP_USER_AGENT = 'http.user_agent' as const;

/**
* Deprecated, use `http.response.body.size` instead.
*
* @example 5493
*
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
*
* @deprecated Replace by `http.response.body.size`.
*/
export const ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED =
'http.response_content_length_uncompressed' as const;
Loading
Loading