-
For context, here is tracesSampler(samplingContext) {
if (samplingContext.parentSampled !== undefined) {
return samplingContext.parentSampled;
}
console.log('[tracesSampler] >>> ', { samplingContext });
return 1;
}, This logs:
I've also instrumented instrumentations: [
getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-fastify': {
requestHook: (span, info) => {
console.log('[fastify] >>>', { span });
},
},
// Disabling this to avoid hitting ENOENT errors
'@opentelemetry/instrumentation-fs': {
enabled: false,
},
'@opentelemetry/instrumentation-http': {
requestHook: (span, request) => {
console.log('[http] >>>', { span });
},
},
}),
], But these fire after This is our entire implementation: import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import opentelemetry from '@opentelemetry/sdk-node';
import { RewriteFrames } from '@sentry/integrations';
import { init } from '@sentry/node';
import {
getClient,
SentryPropagator,
SentrySampler,
SentrySpanProcessor,
setOpenTelemetryContextAsyncContextStrategy,
setupEventContextTrace,
setupGlobalHub,
wrapContextManagerClass,
} from '@sentry/opentelemetry';
import { type Integration } from '@sentry/types';
// eslint-disable-next-line n/no-process-env
const { CONTRA_TRACING_ENABLED } = process.env as Record<string, string>;
export {
type Breadcrumb,
captureException,
captureMessage,
close,
getCurrentHub,
setUser,
type Transaction,
withScope,
} from '@sentry/node';
export { startInactiveSpan, startSpan } from '@sentry/opentelemetry';
export { type Extras } from '@sentry/types';
export const createSentry = ({
integrations,
root,
}: {
integrations?: (integrations: Integration[]) => Integration[];
root: string;
}) => {
if (CONTRA_TRACING_ENABLED === 'true') {
setupGlobalHub();
}
init({
debug: false,
instrumenter: 'otel',
integrations: (defaultIntegrations) => {
const customIntegrations = [
...defaultIntegrations.filter((defaultIntegration) => {
return ![
// Daniel implemented our own version of HttpContext.
'HttpContext',
// Not useful and uses a lot of vertical space on Sentry error reports.
'Modules',
// Associates wrong HTTP requests with the error.
'Http',
// Associates wrong log messages with the error.
'Console',
].includes(defaultIntegration.name);
}),
new RewriteFrames({
root,
}),
];
if (integrations) {
return integrations(customIntegrations);
}
return customIntegrations;
},
normalizeDepth: 5,
tracesSampler(samplingContext) {
if (samplingContext.parentSampled !== undefined) {
return samplingContext.parentSampled;
}
console.log('[tracesSampler] >>> ', { samplingContext });
return 0;
},
});
if (CONTRA_TRACING_ENABLED !== 'true') {
return;
}
const client = getClient();
if (!client) {
return;
}
setupEventContextTrace(client);
// You can wrap whatever local storage context manager you want to use
const SentryContextManager = wrapContextManagerClass(
AsyncLocalStorageContextManager,
);
const sdk = new opentelemetry.NodeSDK({
contextManager: new SentryContextManager(),
instrumentations: [
getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-fastify': {
requestHook: (span, info) => {
console.log('[fastify] >>>', { span });
},
},
// Disabling this to avoid hitting ENOENT errors
'@opentelemetry/instrumentation-fs': {
enabled: false,
},
'@opentelemetry/instrumentation-http': {
requestHook: (span, request) => {
console.log('[http] >>>', { span });
},
},
}),
],
sampler: new SentrySampler(client),
spanProcessor: new SentrySpanProcessor(),
textMapPropagator: new SentryPropagator(),
traceExporter: new OTLPTraceExporter(),
});
// Ensure OpenTelemetry Context & Sentry Hub/Scope is synced
setOpenTelemetryContextAsyncContextStrategy();
sdk.start();
}; |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
CC @lforst |
Beta Was this translation helpful? Give feedback.
-
Hey, we have recently merged a PR to improve this here: #10426 - this is not yet released, but when the upcoming v7.100.0 release is out, this should get more data than before, including the |
Beta Was this translation helpful? Give feedback.
Hey,
we have recently merged a PR to improve this here: #10426 - this is not yet released, but when the upcoming v7.100.0 release is out, this should get more data than before, including the
name
and the initialattributes
. That should be enough to properly sample, hopefully!