@rsdk/core 4.2.5-next.0 → 4.3.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/noop.http-adapter.d.ts +2 -0
- package/dist/noop.http-adapter.js +6 -0
- package/dist/noop.http-adapter.js.map +1 -1
- package/dist/platform.module.d.ts +3 -3
- package/dist/platform.module.js +23 -23
- package/dist/platform.module.js.map +1 -1
- package/dist/tracing/decorators/span.decorator.js +5 -6
- package/dist/tracing/decorators/span.decorator.js.map +1 -1
- package/dist/tracing/index.d.ts +0 -2
- package/dist/tracing/index.js +0 -2
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/services/index.d.ts +0 -1
- package/dist/tracing/services/index.js +0 -1
- package/dist/tracing/services/index.js.map +1 -1
- package/dist/tracing/services/trace.injector.d.ts +4 -4
- package/dist/tracing/services/trace.injector.js +38 -68
- package/dist/tracing/services/trace.injector.js.map +1 -1
- package/dist/tracing/tracing.interceptor.d.ts +3 -5
- package/dist/tracing/tracing.interceptor.js +15 -91
- package/dist/tracing/tracing.interceptor.js.map +1 -1
- package/dist/tracing/tracing.module.d.ts +4 -16
- package/dist/tracing/tracing.module.js +18 -82
- package/dist/tracing/tracing.module.js.map +1 -1
- package/dist/tracing/types.d.ts +11 -0
- package/dist/tracing/types.js +23 -0
- package/dist/tracing/types.js.map +1 -0
- package/dist/tracing/utils/save-async-hooks-context.js +2 -3
- package/dist/tracing/utils/save-async-hooks-context.js.map +1 -1
- package/dist/transport/protocol.detector.d.ts +1 -0
- package/dist/transport/protocol.detector.js +5 -2
- package/dist/transport/protocol.detector.js.map +1 -1
- package/dist/transport/transport.module.js +1 -1
- package/dist/transport/transport.module.js.map +1 -1
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/constants.js +6 -0
- package/dist/types/constants.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +5 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/plugins.d.ts +5 -0
- package/dist/types/plugins.js.map +1 -1
- package/dist/types/tracing.headers-extractor.d.ts +15 -0
- package/dist/types/tracing.headers-extractor.js +67 -0
- package/dist/types/tracing.headers-extractor.js.map +1 -0
- package/dist/types/transports.d.ts +6 -1
- package/dist/types/transports.js.map +1 -1
- package/package.json +13 -12
- package/src/index.ts +0 -3
- package/src/noop.http-adapter.ts +8 -0
- package/src/platform.module.ts +20 -25
- package/src/tracing/decorators/span.decorator.ts +6 -6
- package/src/tracing/index.ts +0 -2
- package/src/tracing/services/index.ts +0 -1
- package/src/tracing/services/trace.injector.ts +49 -92
- package/src/tracing/tracing.interceptor.ts +7 -127
- package/src/tracing/tracing.module.ts +19 -104
- package/src/tracing/types.ts +28 -0
- package/src/tracing/utils/save-async-hooks-context.ts +2 -3
- package/src/transport/protocol.detector.ts +6 -2
- package/src/transport/transport.module.ts +1 -1
- package/src/types/constants.ts +2 -0
- package/src/types/index.ts +2 -0
- package/src/types/plugins.ts +6 -0
- package/src/types/tracing.headers-extractor.ts +51 -0
- package/src/types/transports.ts +8 -1
- package/tsconfig.build.json +1 -1
- package/dist/tracing/active-span.module.d.ts +0 -5
- package/dist/tracing/active-span.module.js +0 -25
- package/dist/tracing/active-span.module.js.map +0 -1
- package/dist/tracing/auto-instrumentations.config.d.ts +0 -1
- package/dist/tracing/auto-instrumentations.config.js +0 -42
- package/dist/tracing/auto-instrumentations.config.js.map +0 -1
- package/dist/tracing/grpc.headers.d.ts +0 -11
- package/dist/tracing/grpc.headers.js +0 -24
- package/dist/tracing/grpc.headers.js.map +0 -1
- package/dist/tracing/http.headers.d.ts +0 -11
- package/dist/tracing/http.headers.js +0 -22
- package/dist/tracing/http.headers.js.map +0 -1
- package/dist/tracing/open-telemetry.interceptor.d.ts +0 -5
- package/dist/tracing/open-telemetry.interceptor.js +0 -83
- package/dist/tracing/open-telemetry.interceptor.js.map +0 -1
- package/dist/tracing/services/active-span.storage.d.ts +0 -17
- package/dist/tracing/services/active-span.storage.js +0 -46
- package/dist/tracing/services/active-span.storage.js.map +0 -1
- package/dist/tracing/services/instrumentation.service.d.ts +0 -3
- package/dist/tracing/services/instrumentation.service.js +0 -25
- package/dist/tracing/services/instrumentation.service.js.map +0 -1
- package/dist/tracing/services/request-id.provider.d.ts +0 -11
- package/dist/tracing/services/request-id.provider.js +0 -13
- package/dist/tracing/services/request-id.provider.js.map +0 -1
- package/src/tracing/active-span.module.ts +0 -13
- package/src/tracing/auto-instrumentations.config.ts +0 -44
- package/src/tracing/grpc.headers.ts +0 -29
- package/src/tracing/http.headers.ts +0 -32
- package/src/tracing/open-telemetry.interceptor.ts +0 -114
- package/src/tracing/services/active-span.storage.ts +0 -32
- package/src/tracing/services/instrumentation.service.ts +0 -20
- package/src/tracing/services/request-id.provider.ts +0 -21
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CallHandler,
|
|
3
|
-
ExecutionContext,
|
|
4
|
-
NestInterceptor,
|
|
5
|
-
} from '@nestjs/common';
|
|
6
|
-
import { trace } from '@opentelemetry/api';
|
|
7
|
-
import {
|
|
8
|
-
X_B3_PARENT_SPAN_ID,
|
|
9
|
-
X_B3_SPAN_ID,
|
|
10
|
-
X_B3_TRACE_ID,
|
|
11
|
-
} from '@opentelemetry/propagator-b3';
|
|
12
|
-
import { api } from '@opentelemetry/sdk-node';
|
|
13
|
-
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
|
14
|
-
import { catchError, mergeMap, Observable, of, throwError } from 'rxjs';
|
|
15
|
-
|
|
16
|
-
import { OpenTelemetryProvider } from './services/request-id.provider';
|
|
17
|
-
import { TraceInjector } from './services';
|
|
18
|
-
|
|
19
|
-
export class OpenTelemetryInterceptor implements NestInterceptor {
|
|
20
|
-
intercept(
|
|
21
|
-
_context: ExecutionContext,
|
|
22
|
-
next: CallHandler<any>,
|
|
23
|
-
): Observable<any> | Promise<Observable<any>> {
|
|
24
|
-
const tracer = trace.getTracer('@rsdk/open-telemetry', '1.0.0');
|
|
25
|
-
|
|
26
|
-
const spanName = TraceInjector.createSpanName(
|
|
27
|
-
OpenTelemetryInterceptor.name,
|
|
28
|
-
'intercept',
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Создаем новый спан
|
|
33
|
-
*/
|
|
34
|
-
const span = tracer.startSpan(spanName, {});
|
|
35
|
-
|
|
36
|
-
const openTelemetryValues = OpenTelemetryProvider.getOrThrow();
|
|
37
|
-
|
|
38
|
-
const parentSpanId = openTelemetryValues[X_B3_PARENT_SPAN_ID];
|
|
39
|
-
if (parentSpanId) {
|
|
40
|
-
(span as any).parentSpanId = parentSpanId;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const spanId = openTelemetryValues[X_B3_SPAN_ID];
|
|
44
|
-
/**
|
|
45
|
-
* После создания контекста ранее при входе в приложение, у нас новый спан ид
|
|
46
|
-
* мы перетираем значением которе получили через заголовок
|
|
47
|
-
* в рамках приложения он корректный, но при переходе из одного приложения в другой - слетает
|
|
48
|
-
* и чтобы 100% все было норм, мы всегда патчим его
|
|
49
|
-
*/
|
|
50
|
-
if (spanId) {
|
|
51
|
-
span.spanContext().spanId = spanId;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const traceId = openTelemetryValues[X_B3_TRACE_ID];
|
|
55
|
-
/**
|
|
56
|
-
* Патчим трайс ид, причина выше
|
|
57
|
-
*/
|
|
58
|
-
if (traceId) {
|
|
59
|
-
span.spanContext().traceId = traceId;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Обычно самая первая точка входа это фронтовый запрос, который содержит некие заголовки хттп
|
|
63
|
-
* мы их кладем в рутовый спан
|
|
64
|
-
*/
|
|
65
|
-
if (openTelemetryValues.http) {
|
|
66
|
-
span.setAttribute(
|
|
67
|
-
SemanticAttributes.HTTP_METHOD,
|
|
68
|
-
openTelemetryValues.http.httpMethod,
|
|
69
|
-
);
|
|
70
|
-
span.setAttribute(
|
|
71
|
-
SemanticAttributes.HTTP_URL,
|
|
72
|
-
openTelemetryValues.http.httpUrl,
|
|
73
|
-
);
|
|
74
|
-
span.setAttribute(
|
|
75
|
-
SemanticAttributes.HTTP_ROUTE,
|
|
76
|
-
openTelemetryValues.http.httpRoute,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Чтобы пробросить пропатченный спан нужно запустить две строчки ниже:
|
|
81
|
-
* 1) создаем контекст в котором активный спан перебиваем новым
|
|
82
|
-
* 2) созданный контекст ставим основным и в нем запускаем под процесс
|
|
83
|
-
*/
|
|
84
|
-
const spanContext = api.trace.setSpan(api.context.active(), span);
|
|
85
|
-
|
|
86
|
-
return new Observable((observer) => {
|
|
87
|
-
api.context.with(spanContext, () => {
|
|
88
|
-
next
|
|
89
|
-
.handle()
|
|
90
|
-
.pipe(
|
|
91
|
-
mergeMap((result) => {
|
|
92
|
-
TraceInjector.enrich(span, result);
|
|
93
|
-
span.end();
|
|
94
|
-
return of(result);
|
|
95
|
-
}),
|
|
96
|
-
catchError((error) => {
|
|
97
|
-
TraceInjector.recordAndRethrow(error, span);
|
|
98
|
-
span.end();
|
|
99
|
-
return throwError(() => error);
|
|
100
|
-
}),
|
|
101
|
-
)
|
|
102
|
-
.subscribe({
|
|
103
|
-
complete: () => {
|
|
104
|
-
observer.complete();
|
|
105
|
-
},
|
|
106
|
-
error: (error) => {
|
|
107
|
-
observer.error(error);
|
|
108
|
-
},
|
|
109
|
-
next: (res) => observer.next(res),
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import type { Span } from '@opentelemetry/api';
|
|
3
|
-
import { api } from '@opentelemetry/sdk-node';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Обертка вокруг `api.trace.getActiveSpan()`
|
|
7
|
-
*/
|
|
8
|
-
@Injectable()
|
|
9
|
-
export class ActiveSpanStorage {
|
|
10
|
-
/**
|
|
11
|
-
* Так как этот сервис используется в разных местах, чтобы не усложнять существующий код путем проксирования модулей и сервисов
|
|
12
|
-
* после создания ложим инстанс в эту статик переменную
|
|
13
|
-
*/
|
|
14
|
-
private static instance: ActiveSpanStorage | undefined;
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
if (!ActiveSpanStorage.instance) {
|
|
18
|
-
ActiveSpanStorage.instance = this;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static getInstance(): ActiveSpanStorage | undefined {
|
|
23
|
-
return ActiveSpanStorage.instance;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Получает новое значение в контекст
|
|
28
|
-
*/
|
|
29
|
-
getActiveSpan(): Span | undefined {
|
|
30
|
-
return api.trace.getActiveSpan();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
|
|
3
|
-
import { TracingInterceptor } from '../tracing.interceptor';
|
|
4
|
-
|
|
5
|
-
import { TraceInjector } from './trace.injector';
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class InstrumentationService {
|
|
9
|
-
public injectWrapTraceInjector(): void {
|
|
10
|
-
/**
|
|
11
|
-
* Оборачиваем интерцептор в логику которая несет с собою асинк локал сторадж с traceId, spanId
|
|
12
|
-
*/
|
|
13
|
-
TraceInjector.wrap(
|
|
14
|
-
TracingInterceptor.prototype,
|
|
15
|
-
TracingInterceptor.prototype['intercept'],
|
|
16
|
-
undefined,
|
|
17
|
-
true,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
X_B3_PARENT_SPAN_ID,
|
|
3
|
-
X_B3_SPAN_ID,
|
|
4
|
-
X_B3_TRACE_ID,
|
|
5
|
-
} from '@opentelemetry/propagator-b3';
|
|
6
|
-
import { createAsyncContextProvider } from '@rsdk/actx';
|
|
7
|
-
|
|
8
|
-
export const RequestIdProvider = createAsyncContextProvider<string>({
|
|
9
|
-
name: 'RequestId',
|
|
10
|
-
rewritable: false,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const OpenTelemetryProvider = createAsyncContextProvider<{
|
|
14
|
-
[X_B3_SPAN_ID]?: string;
|
|
15
|
-
[X_B3_TRACE_ID]?: string;
|
|
16
|
-
[X_B3_PARENT_SPAN_ID]?: string;
|
|
17
|
-
http?: { httpMethod: string; httpUrl: string; httpRoute: string };
|
|
18
|
-
}>({
|
|
19
|
-
name: 'OpenTelemetryPropagation',
|
|
20
|
-
rewritable: false,
|
|
21
|
-
});
|