-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathopentelemetry.ts
62 lines (50 loc) · 2.02 KB
/
opentelemetry.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { RemixInstrumentation } from 'opentelemetry-instrumentation-remix';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration } from '@sentry/core';
import { generateInstrumentOnce, getClient, spanToJSON } from '@sentry/node';
import type { Client, IntegrationFn, Span } from '@sentry/types';
import type { RemixOptions } from '../remixOptions';
const INTEGRATION_NAME = 'Remix';
const instrumentRemix = generateInstrumentOnce<RemixOptions>(
INTEGRATION_NAME,
(_options?: RemixOptions) =>
new RemixInstrumentation({
actionFormDataAttributes: _options?.sendDefaultPii ? _options?.captureActionFormDataKeys : undefined,
}),
);
const _remixIntegration = (() => {
return {
name: 'Remix',
setupOnce() {
const client = getClient();
const options = client?.getOptions();
instrumentRemix(options);
},
setup(client: Client) {
client.on('spanStart', span => {
addRemixSpanAttributes(span);
});
},
};
}) satisfies IntegrationFn;
const addRemixSpanAttributes = (span: Span): void => {
const attributes = spanToJSON(span).data || {};
// this is one of: loader, action, requestHandler
const type = attributes['code.function'];
// If this is already set, or we have no remix span, no need to process again...
if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || !type) {
return;
}
// `requestHandler` span from `opentelemetry-instrumentation-remix` is the main server span.
// It should be marked as the `http.server` operation.
// The incoming requests are skipped by the custom `RemixHttpIntegration` package.
// All other spans are marked as `remix` operations with their specific type [loader, action]
const op = type === 'requestHandler' ? 'http.server' : `${type}.remix`;
span.setAttributes({
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.remix',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
});
};
/**
* Instrumentation for aws-sdk package
*/
export const remixIntegration = defineIntegration(_remixIntegration);