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
8 changes: 4 additions & 4 deletions packages/core/src/integrations/http/server-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
} from '../../semanticAttributes';
import { safeMathRandom } from '../../utils/randomSafeContext';
import { SPAN_KIND } from '../../spanKind';
import type { SpanAttributes } from '../../types/span';
import type { SpanStatus } from '../../types/spanStatus';

Expand Down Expand Up @@ -277,10 +278,9 @@ function buildServerSpanWrap(
return startSpanManual(
{
name,
// SpanKind.SERVER = 1; pass this so the OTel sampler infers
// op='http.server' rather than 'http', which it does for
// SpanKind.INTERNAL = 0, the default
kind: 1,
// Pass SERVER so the OTel sampler infers op='http.server' rather than
// 'http', which it does for the INTERNAL default.
kind: SPAN_KIND.SERVER,
attributes: {
// Sentry-specific attributes
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/shared-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export {
} from './utils/request';
export type { MaxRequestBodySize } from './utils/request';
export { DEFAULT_ENVIRONMENT, DEV_ENVIRONMENT } from './constants';
export { SPAN_KIND } from './spanKind';
export type { SpanKindValue } from './spanKind';
export { addBreadcrumb } from './breadcrumbs';
export { functionToStringIntegration } from './integrations/functiontostring';
// eslint-disable-next-line typescript/no-deprecated
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/spanKind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* The kind of a span, mirroring OpenTelemetry's `SpanKind` enum values.
*
* Exported as a plain const object so SDK code can set a span's kind without
* importing `@opentelemetry/api` just for the enum. The numeric values must
* stay in sync with OpenTelemetry's `SpanKind` since they are passed through to
* the underlying OTel span and sampler.
*/
export const SPAN_KIND = {
INTERNAL: 0,
SERVER: 1,
CLIENT: 2,
PRODUCER: 3,
CONSUMER: 4,
} as const;

export type SpanKindValue = (typeof SPAN_KIND)[keyof typeof SPAN_KIND];
3 changes: 2 additions & 1 deletion packages/core/src/types/startSpanOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Scope } from '../scope';
import type { SpanKindValue } from '../spanKind';
import type { SpanLink } from './link';
import type { Span, SpanAttributes, SpanTimeInput } from './span';

Expand Down Expand Up @@ -40,7 +41,7 @@ export interface StartSpanOptions {
* span kind on the underlying OTel span, which affects how the span is
* displayed and sampled.
*/
kind?: 0 | 1 | 2 | 3 | 4;
kind?: SpanKindValue;

/**
* If provided, make the new span a child of this span.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getTraceData,
LRUMap,
shouldPropagateTraceForUrl,
SPAN_KIND,
SPAN_STATUS_ERROR,
startInactiveSpan,
withActiveSpan,
Expand Down Expand Up @@ -53,9 +54,6 @@ import type {
} from './internal-types';
import type { UndiciInstrumentationConfig, UndiciRequest } from './types';

// `SpanKind.CLIENT`, inlined to avoid importing from `@opentelemetry/api`.
const SPAN_KIND_CLIENT = 2;

/** Replaces OTel's `safeExecuteInTheMiddle`: run `fn`, route any error to `onError`, and swallow it. */
function safeExecute<T>(fn: () => T, onError: (error: unknown) => void): T | undefined {
try {
Expand Down Expand Up @@ -246,7 +244,7 @@ export class UndiciInstrumentation {

const span = startInactiveSpan({
name: requestMethod === '_OTHER' ? 'HTTP' : requestMethod,
kind: SPAN_KIND_CLIENT,
kind: SPAN_KIND.CLIENT,
attributes,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
*/

import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';
import { SpanKind } from '@opentelemetry/api';
import type { BatchLoadFn, DataLoader, DataLoaderConstructor } from './types';
import { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/core';
import {
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_KIND,
startSpan,
} from '@sentry/core';

const MODULE_NAME = 'dataloader';
const PACKAGE_NAME = '@sentry/instrumentation-dataloader';
Expand Down Expand Up @@ -152,7 +157,7 @@ export class DataloaderInstrumentation extends InstrumentationBase {
return startSpan(
{
name: getSpanName(this, 'load'),
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: getSpanOp('load'),
Expand Down Expand Up @@ -190,7 +195,7 @@ export class DataloaderInstrumentation extends InstrumentationBase {
return startSpan(
{
name: getSpanName(this, 'loadMany'),
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: getSpanOp('loadMany'),
Expand All @@ -216,7 +221,7 @@ export class DataloaderInstrumentation extends InstrumentationBase {
return startSpan(
{
name: getSpanName(this, 'prime'),
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: getSpanOp('prime'),
Expand All @@ -242,7 +247,7 @@ export class DataloaderInstrumentation extends InstrumentationBase {
return startSpan(
{
name: getSpanName(this, 'clear'),
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: getSpanOp('clear'),
Expand All @@ -268,7 +273,7 @@ export class DataloaderInstrumentation extends InstrumentationBase {
return startSpan(
{
name: getSpanName(this, 'clearAll'),
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: getSpanOp('clearAll'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
* - Span creation extracted here and migrated to the @sentry/core API; origin folded into span creation
*/

import { SpanKind, TraceFlags } from '@opentelemetry/api';
import { TraceFlags } from '@opentelemetry/api';
import type { Span, SpanAttributes, SpanLink } from '@sentry/core';
import {
getTraceData,
propagationContextFromHeaders,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_KIND,
SPAN_STATUS_ERROR,
startInactiveSpan,
} from '@sentry/core';
Expand Down Expand Up @@ -96,7 +97,7 @@ export function startConsumerSpan({ topic, message, operationType, links, attrib

return startInactiveSpan({
name: `${operationName} ${topic}`,
kind: operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE ? SpanKind.CLIENT : SpanKind.CONSUMER,
kind: operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE ? SPAN_KIND.CLIENT : SPAN_KIND.CONSUMER,
links,
attributes: {
...attributes,
Expand All @@ -118,7 +119,7 @@ export function startConsumerSpan({ topic, message, operationType, links, attrib
export function startProducerSpan(topic: string, message: Message): Span {
const span = startInactiveSpan({
name: `send ${topic}`,
kind: SpanKind.PRODUCER,
kind: SPAN_KIND.PRODUCER,
attributes: {
[ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,
[ATTR_MESSAGING_DESTINATION_NAME]: topic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

/* oxlint-disable typescript/no-deprecated */

import { SpanKind } from '@opentelemetry/api';
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';
import type { Span, SpanAttributes } from '@sentry/core';
import {
getActiveSpan,
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_KIND,
SPAN_STATUS_ERROR,
startSpan,
} from '@sentry/core';
Expand Down Expand Up @@ -143,7 +143,7 @@ export class KnexInstrumentation extends InstrumentationBase<InstrumentationConf
return startSpan(
{
name: utils.getName(name, operation, table),
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes,
parentSpan,
onlyIfParent: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs
*/

import { SpanKind } from '@opentelemetry/api';
import type { Span, SpanAttributes } from '@sentry/core';
import {
getActiveSpan,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_KIND,
SPAN_STATUS_ERROR,
startInactiveSpan,
withActiveSpan,
Expand Down Expand Up @@ -203,7 +203,7 @@ export function startMongoSpan(attributes: SpanAttributes): Span {
return startInactiveSpan({
// eslint-disable-next-line typescript/no-deprecated
name: `mongodb.${attributes[ATTR_DB_OPERATION] || 'command'}`,
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs
*/

import { SpanKind } from '@opentelemetry/api';
import {
type InstrumentationConfig,
InstrumentationBase,
Expand All @@ -22,6 +21,7 @@ import {
getActiveSpan,
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_KIND,
startInactiveSpan,
withActiveSpan,
} from '@sentry/core';
Expand Down Expand Up @@ -306,7 +306,7 @@ export class MongooseInstrumentation extends InstrumentationBase<Instrumentation

return startInactiveSpan({
name: `mongoose.${modelName}.${operation}`,
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes,
parentSpan,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
* - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs
*/

import { SpanKind } from '@opentelemetry/api';
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';
import type { SpanAttributes } from '@sentry/core';
import { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_STATUS_ERROR, startInactiveSpan } from '@sentry/core';
import {
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_KIND,
SPAN_STATUS_ERROR,
startInactiveSpan,
} from '@sentry/core';
import { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';
import type { Connection, FormatFunction, Query, QueryError, QueryOptions } from './mysql2-types';
import { ATTR_DB_STATEMENT, ATTR_DB_SYSTEM, DB_SYSTEM_VALUE_MYSQL } from './semconv';
Expand Down Expand Up @@ -118,7 +123,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<InstrumentationCo

const span = startInactiveSpan({
name: getSpanName(query),
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
* enhancedDatabaseReporting, addSqlCommenterCommentToQueries)
*/

import { SpanKind } from '@opentelemetry/api';
import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';
import type { Span } from '@sentry/core';
import { getActiveSpan, SDK_VERSION, SPAN_STATUS_ERROR, startInactiveSpan, withActiveSpan } from '@sentry/core';
import {
getActiveSpan,
SDK_VERSION,
SPAN_KIND,
SPAN_STATUS_ERROR,
startInactiveSpan,
withActiveSpan,
} from '@sentry/core';
import { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';
import { SpanNames } from './enums/SpanNames';
import type {
Expand Down Expand Up @@ -157,7 +163,7 @@ export class PgInstrumentation extends InstrumentationBase<PgInstrumentationConf

const span = startInactiveSpan({
name: SpanNames.CONNECT,
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes: utils.getSemanticAttributesFromConnection(this),
});

Expand Down Expand Up @@ -277,7 +283,7 @@ export class PgInstrumentation extends InstrumentationBase<PgInstrumentationConf

const span = startInactiveSpan({
name: SpanNames.POOL_CONNECT,
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes: utils.getSemanticAttributesFromPoolConnection(this.options),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
* - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs
*/

import { SpanKind } from '@opentelemetry/api';
import type { Span, SpanAttributes } from '@sentry/core';
import { getActiveSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_STATUS_ERROR, startInactiveSpan } from '@sentry/core';
import {
getActiveSpan,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_KIND,
SPAN_STATUS_ERROR,
startInactiveSpan,
} from '@sentry/core';
import { AttributeNames } from './enums/AttributeNames';
import { SpanNames } from './enums/SpanNames';
import type {
Expand Down Expand Up @@ -173,7 +178,7 @@ export function handleConfigQuery(
const spanName = getQuerySpanName(dbName, queryConfig);
const span = startInactiveSpan({
name: spanName,
kind: SpanKind.CLIENT,
kind: SPAN_KIND.CLIENT,
attributes: {
...getSemanticAttributesFromConnection(connectionParameters),
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
* - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs
*/

import { SpanKind } from '@opentelemetry/api';
import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';
import type { Span, SpanAttributes } from '@sentry/core';
import {
getActiveSpan,
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_KIND,
SPAN_STATUS_ERROR,
startInactiveSpan,
} from '@sentry/core';
Expand Down Expand Up @@ -126,7 +126,7 @@ export class IORedisInstrumentation extends InstrumentationBase<IORedisInstrumen
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
};

const span = startInactiveSpan({ name: cmd.name, kind: SpanKind.CLIENT, attributes });
const span = startInactiveSpan({ name: cmd.name, kind: SPAN_KIND.CLIENT, attributes });

try {
const result = original.apply(this, args);
Expand Down Expand Up @@ -167,7 +167,7 @@ export class IORedisInstrumentation extends InstrumentationBase<IORedisInstrumen
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
};

const span = startInactiveSpan({ name: 'connect', kind: SpanKind.CLIENT, attributes });
const span = startInactiveSpan({ name: 'connect', kind: SPAN_KIND.CLIENT, attributes });

try {
const result = original.apply(this, args) as Promise<unknown> | undefined;
Expand Down
Loading
Loading