@ogcio/o11y-sdk-node 0.1.0-beta.6 → 0.1.0-beta.7
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 +7 -0
- package/README.md +59 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -0
- package/dist/lib/exporter/console.d.ts +3 -0
- package/dist/lib/exporter/console.js +16 -0
- package/dist/lib/exporter/grpc.d.ts +3 -0
- package/dist/lib/{grpc.js → exporter/grpc.js} +9 -5
- package/dist/lib/exporter/http.d.ts +3 -0
- package/dist/lib/{http.js → exporter/http.js} +9 -5
- package/dist/lib/index.d.ts +17 -5
- package/dist/lib/instrumentation.node.js +26 -7
- package/dist/lib/options.d.ts +5 -3
- package/dist/lib/processor/enrich-span-processor.d.ts +11 -0
- package/dist/lib/processor/enrich-span-processor.js +22 -0
- package/dist/lib/traces.d.ts +1 -0
- package/dist/lib/traces.js +4 -0
- package/dist/lib/url-sampler.d.ts +3 -2
- package/dist/lib/url-sampler.js +5 -8
- package/dist/lib/utils.d.ts +4 -2
- package/dist/lib/utils.js +8 -3
- package/dist/package.json +18 -14
- package/dist/vitest.config.js +15 -1
- package/index.ts +2 -2
- package/lib/exporter/console.ts +27 -0
- package/lib/{grpc.ts → exporter/grpc.ts} +13 -7
- package/lib/{http.ts → exporter/http.ts} +13 -7
- package/lib/index.ts +24 -4
- package/lib/instrumentation.node.ts +48 -9
- package/lib/options.ts +5 -3
- package/lib/processor/enrich-span-processor.ts +39 -0
- package/lib/traces.ts +5 -0
- package/lib/url-sampler.ts +13 -14
- package/lib/utils.ts +16 -4
- package/package.json +18 -14
- package/test/enrich-span-processor.test.ts +105 -0
- package/test/index.test.ts +9 -0
- package/test/integration/integration.test.ts +21 -0
- package/test/integration/run.sh +2 -2
- package/test/node-config.test.ts +49 -36
- package/test/url-sampler.test.ts +215 -0
- package/vitest.config.ts +15 -1
- package/dist/lib/console.d.ts +0 -3
- package/dist/lib/console.js +0 -12
- package/dist/lib/grpc.d.ts +0 -3
- package/dist/lib/http.d.ts +0 -3
- package/lib/console.ts +0 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.0-beta.7](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-node@v0.1.0-beta.6...@ogcio/o11y-sdk-node@v0.1.0-beta.7) (2025-02-18)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **sdk-node:** add span customization AB[#25358](https://github.com/ogcio/o11y/issues/25358) ([46ba97b](https://github.com/ogcio/o11y/commit/46ba97bac4004ff326a954592f45213ce0e4d683))
|
|
9
|
+
|
|
3
10
|
## [0.1.0-beta.6](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-node@v0.1.0-beta.5...@ogcio/o11y-sdk-node@v0.1.0-beta.6) (2025-02-06)
|
|
4
11
|
|
|
5
12
|
|
package/README.md
CHANGED
|
@@ -27,6 +27,15 @@ import("@ogcio/o11y-sdk-node/lib/index").then((sdk) =>
|
|
|
27
27
|
sdk.instrumentNode({
|
|
28
28
|
serviceName: "node-microservice",
|
|
29
29
|
collectorUrl: "http://localhost:4317",
|
|
30
|
+
resourceAttributes: {
|
|
31
|
+
"team.infra.cluster": "dev-01",
|
|
32
|
+
"team.infra.pod": "01",
|
|
33
|
+
"team.service.type": "fastify",
|
|
34
|
+
},
|
|
35
|
+
spanAttributes: {
|
|
36
|
+
"signal.namespace": "documentation",
|
|
37
|
+
},
|
|
38
|
+
ignoreUrls: [{ type: "equals", url: "/api/health" }],
|
|
30
39
|
}),
|
|
31
40
|
);
|
|
32
41
|
```
|
|
@@ -47,6 +56,56 @@ Or setup inside your package.json
|
|
|
47
56
|
}
|
|
48
57
|
```
|
|
49
58
|
|
|
59
|
+
## Span Customization
|
|
60
|
+
|
|
61
|
+
It is possible to customize spans such as traces and logs globally or in a single code statement using predefined functions.
|
|
62
|
+
|
|
63
|
+
### Global Configuration
|
|
64
|
+
|
|
65
|
+
In the SDK configuration, you can set the following properties:
|
|
66
|
+
|
|
67
|
+
- `spanAttributes` Object containing static properties or functions used to evaluate custom attributes for every logs and traces.
|
|
68
|
+
- `resourceAttributes` Object containing static properties used as resources attributes for any signal.
|
|
69
|
+
- `traceRatio` Faction value from 0 to 1, used by TraceIdRatioBasedSampler which it deterministically samples a percentage of traces that you pass in as a parameter.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
function generateRandomString(): string {
|
|
73
|
+
return Math.random() + "_" + Date.now();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
instrumentNode({
|
|
77
|
+
resourceAttributes: {
|
|
78
|
+
"property.name.one": "value_one",
|
|
79
|
+
"property.name.two": "value_two",
|
|
80
|
+
},
|
|
81
|
+
spanAttributes: {
|
|
82
|
+
"custom.span.value": "example",
|
|
83
|
+
"custom.span.value_with_function": generateRandomString,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Edit Active Span
|
|
89
|
+
|
|
90
|
+
Using `getActiveSpan` function, you can access to current transaction span and customize it.
|
|
91
|
+
|
|
92
|
+
You can use the function everywhere in your code, and set some custom attributes that are enabled for that single span
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { getActiveSpan } from "@ogcio/o11y-sdk-node";
|
|
96
|
+
|
|
97
|
+
async function routes(app: FastifyInstance) {
|
|
98
|
+
app.get("/", async (req, reply) => {
|
|
99
|
+
// validation and business logic
|
|
100
|
+
|
|
101
|
+
// set span attribute
|
|
102
|
+
getActiveSpan()?.setAttribute("business.info", "dummy");
|
|
103
|
+
|
|
104
|
+
reply.status(200).send(response);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
50
109
|
## Sending Custom Metrics
|
|
51
110
|
|
|
52
111
|
This package gives the possibility to send custom metrics and define them as desired in the code, you can choose between sync metrics and observable async metrics.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NodeSDK } from "@opentelemetry/sdk-node";
|
|
2
|
-
import type { NodeSDKConfig } from "./lib/index.js";
|
|
3
2
|
import buildNodeInstrumentation from "./lib/instrumentation.node.js";
|
|
4
3
|
export type * from "./lib/index.js";
|
|
5
|
-
export type {
|
|
4
|
+
export type { NodeSDK };
|
|
6
5
|
export { buildNodeInstrumentation as instrumentNode };
|
|
7
6
|
export * from "./lib/metrics.js";
|
|
7
|
+
export * from "./lib/traces.js";
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ConsoleLogRecordExporter, SimpleLogRecordProcessor, } from "@opentelemetry/sdk-logs";
|
|
2
|
+
import { metrics } from "@opentelemetry/sdk-node";
|
|
3
|
+
import { ConsoleSpanExporter, SimpleSpanProcessor, } from "@opentelemetry/sdk-trace-base";
|
|
4
|
+
import { EnrichSpanProcessor } from "../processor/enrich-span-processor.js";
|
|
5
|
+
export default function buildConsoleExporters(config) {
|
|
6
|
+
return {
|
|
7
|
+
spans: [
|
|
8
|
+
new SimpleSpanProcessor(new ConsoleSpanExporter()),
|
|
9
|
+
new EnrichSpanProcessor(config.spanAttributes),
|
|
10
|
+
],
|
|
11
|
+
metrics: new metrics.PeriodicExportingMetricReader({
|
|
12
|
+
exporter: new metrics.ConsoleMetricExporter(),
|
|
13
|
+
}),
|
|
14
|
+
logs: [new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { LogRecordProcessorMap } from "./utils.js";
|
|
2
1
|
import { metrics } from "@opentelemetry/sdk-node";
|
|
3
2
|
import { CompressionAlgorithm } from "@opentelemetry/otlp-exporter-base";
|
|
4
3
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-grpc";
|
|
5
4
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-grpc";
|
|
6
5
|
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-grpc";
|
|
6
|
+
import { LogRecordProcessorMap, SpanProcessorMap } from "../utils.js";
|
|
7
|
+
import { EnrichSpanProcessor } from "../processor/enrich-span-processor.js";
|
|
7
8
|
export default function buildGrpcExporters(config) {
|
|
8
9
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
spans: [
|
|
11
|
+
new SpanProcessorMap[config.collectorMode ?? "batch"](new OTLPTraceExporter({
|
|
12
|
+
url: `${config.collectorUrl}`,
|
|
13
|
+
compression: CompressionAlgorithm.GZIP,
|
|
14
|
+
})),
|
|
15
|
+
new EnrichSpanProcessor(config.spanAttributes),
|
|
16
|
+
],
|
|
13
17
|
metrics: new metrics.PeriodicExportingMetricReader({
|
|
14
18
|
exporter: new OTLPMetricExporter({
|
|
15
19
|
url: `${config.collectorUrl}`,
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { LogRecordProcessorMap } from "./utils.js";
|
|
2
1
|
import { metrics } from "@opentelemetry/sdk-node";
|
|
3
2
|
import { CompressionAlgorithm } from "@opentelemetry/otlp-exporter-base";
|
|
4
3
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
5
4
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
6
5
|
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
6
|
+
import { LogRecordProcessorMap, SpanProcessorMap } from "../utils.js";
|
|
7
|
+
import { EnrichSpanProcessor } from "../processor/enrich-span-processor.js";
|
|
7
8
|
export default function buildHttpExporters(config) {
|
|
8
9
|
if (config.collectorUrl.endsWith("/")) {
|
|
9
10
|
config.collectorUrl = config.collectorUrl.slice(0, -1);
|
|
10
11
|
}
|
|
11
12
|
return {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
spans: [
|
|
14
|
+
new SpanProcessorMap[config.collectorMode ?? "batch"](new OTLPTraceExporter({
|
|
15
|
+
url: `${config.collectorUrl}/v1/traces`,
|
|
16
|
+
compression: CompressionAlgorithm.GZIP,
|
|
17
|
+
})),
|
|
18
|
+
new EnrichSpanProcessor(config.spanAttributes),
|
|
19
|
+
],
|
|
16
20
|
metrics: new metrics.PeriodicExportingMetricReader({
|
|
17
21
|
exporter: new OTLPMetricExporter({
|
|
18
22
|
url: `${config.collectorUrl}/v1/metrics`,
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface
|
|
1
|
+
export interface NodeSDKConfig {
|
|
2
2
|
/**
|
|
3
3
|
* The opentelemetry collector entrypoint GRPC url.
|
|
4
4
|
* If the collectoUrl is null or undefined, the instrumentation will not be activated.
|
|
@@ -32,8 +32,20 @@ interface SDKConfig {
|
|
|
32
32
|
* @default []
|
|
33
33
|
*/
|
|
34
34
|
ignoreUrls?: SamplerCondition[];
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Object containing static properties or functions used to evaluate custom attributes for every logs and traces.
|
|
37
|
+
*/
|
|
38
|
+
spanAttributes?: Record<string, SignalAttributeValue | (() => SignalAttributeValue)>;
|
|
39
|
+
/**
|
|
40
|
+
* Object containing static properties used as resources attributes for the Node SDK initialization.
|
|
41
|
+
*/
|
|
42
|
+
resourceAttributes?: Record<string, SignalAttributeValue>;
|
|
43
|
+
/**
|
|
44
|
+
* Faction value from 0 to 1, used by TraceIdRatioBasedSampler which it deterministically samples a percentage of traces that you pass in as a parameter.
|
|
45
|
+
*
|
|
46
|
+
* @default 1
|
|
47
|
+
*/
|
|
48
|
+
traceRatio?: number;
|
|
37
49
|
/**
|
|
38
50
|
* Flag to enable or disable the tracing for node:fs module
|
|
39
51
|
*
|
|
@@ -41,7 +53,7 @@ export interface NodeSDKConfig extends SDKConfig {
|
|
|
41
53
|
*/
|
|
42
54
|
enableFS?: boolean;
|
|
43
55
|
/**
|
|
44
|
-
*
|
|
56
|
+
* Protocol used to send signals.
|
|
45
57
|
*
|
|
46
58
|
* @default grpc
|
|
47
59
|
*/
|
|
@@ -51,7 +63,7 @@ export interface SamplerCondition {
|
|
|
51
63
|
type: "endsWith" | "includes" | "equals";
|
|
52
64
|
url: string;
|
|
53
65
|
}
|
|
66
|
+
export type SignalAttributeValue = string | number | boolean;
|
|
54
67
|
export type SDKCollectorMode = "single" | "batch";
|
|
55
68
|
export type SDKProtocol = "grpc" | "http" | "console";
|
|
56
69
|
export type SDKLogLevel = "NONE" | "ERROR" | "WARN" | "INFO" | "DEBUG" | "VERBOSE" | "ALL";
|
|
57
|
-
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import buildHttpExporters from "./http.js";
|
|
3
|
-
import buildGrpcExporters from "./grpc.js";
|
|
4
|
-
import buildConsoleExporters from "./console.js";
|
|
5
|
-
import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
|
|
1
|
+
import { diag, DiagConsoleLogger, DiagLogLevel, } from "@opentelemetry/api";
|
|
6
2
|
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
|
|
7
3
|
import { W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
4
|
+
import { NodeSDK, resources } from "@opentelemetry/sdk-node";
|
|
5
|
+
import { AlwaysOffSampler, ParentBasedSampler, TraceIdRatioBasedSampler, } from "@opentelemetry/sdk-trace-base";
|
|
8
6
|
import packageJson from "../package.json" with { type: "json" };
|
|
7
|
+
import buildConsoleExporters from "./exporter/console.js";
|
|
8
|
+
import buildGrpcExporters from "./exporter/grpc.js";
|
|
9
|
+
import buildHttpExporters from "./exporter/http.js";
|
|
9
10
|
import { UrlSampler } from "./url-sampler.js";
|
|
10
11
|
export default function buildNodeInstrumentation(config) {
|
|
11
12
|
if (!config) {
|
|
@@ -30,6 +31,14 @@ export default function buildNodeInstrumentation(config) {
|
|
|
30
31
|
else {
|
|
31
32
|
exporter = buildGrpcExporters(config);
|
|
32
33
|
}
|
|
34
|
+
const urlSampler = new UrlSampler(config.ignoreUrls, new TraceIdRatioBasedSampler(config.traceRatio ?? 1));
|
|
35
|
+
const mainSampler = new ParentBasedSampler({
|
|
36
|
+
root: urlSampler,
|
|
37
|
+
remoteParentSampled: urlSampler,
|
|
38
|
+
remoteParentNotSampled: new AlwaysOffSampler(),
|
|
39
|
+
localParentSampled: urlSampler,
|
|
40
|
+
localParentNotSampled: new AlwaysOffSampler(),
|
|
41
|
+
});
|
|
33
42
|
try {
|
|
34
43
|
diag.setLogger(new DiagConsoleLogger(), config.diagLogLevel
|
|
35
44
|
? DiagLogLevel[config.diagLogLevel]
|
|
@@ -38,18 +47,28 @@ export default function buildNodeInstrumentation(config) {
|
|
|
38
47
|
resource: new resources.Resource({
|
|
39
48
|
"o11y.sdk.name": packageJson.name,
|
|
40
49
|
"o11y.sdk.version": packageJson.version,
|
|
50
|
+
...config.resourceAttributes,
|
|
41
51
|
}),
|
|
52
|
+
spanProcessors: exporter.spans,
|
|
42
53
|
serviceName: config.serviceName,
|
|
43
|
-
traceExporter: exporter.traces,
|
|
44
54
|
metricReader: exporter.metrics,
|
|
45
55
|
logRecordProcessors: exporter.logs,
|
|
46
|
-
sampler:
|
|
56
|
+
sampler: mainSampler,
|
|
47
57
|
textMapPropagator: new W3CTraceContextPropagator(),
|
|
48
58
|
instrumentations: [
|
|
49
59
|
getNodeAutoInstrumentations({
|
|
50
60
|
"@opentelemetry/instrumentation-fs": {
|
|
51
61
|
enabled: config.enableFS ?? false,
|
|
52
62
|
},
|
|
63
|
+
"@opentelemetry/instrumentation-pino": {
|
|
64
|
+
logHook: (_span, record, _level) => {
|
|
65
|
+
if (config.spanAttributes != undefined) {
|
|
66
|
+
for (const [key, value] of Object.entries(config.spanAttributes)) {
|
|
67
|
+
record[key] = typeof value === "function" ? value() : value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
},
|
|
53
72
|
}),
|
|
54
73
|
],
|
|
55
74
|
});
|
package/dist/lib/options.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
2
|
+
import type { metrics } from "@opentelemetry/sdk-node";
|
|
3
|
+
import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
2
4
|
export type Exporters = {
|
|
3
|
-
|
|
5
|
+
spans: SpanProcessor[];
|
|
4
6
|
metrics: metrics.MetricReader;
|
|
5
|
-
logs:
|
|
7
|
+
logs: LogRecordProcessor[];
|
|
6
8
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context } from "@opentelemetry/api";
|
|
2
|
+
import { ReadableSpan, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
import { SignalAttributeValue } from "../index.js";
|
|
4
|
+
export declare class EnrichSpanProcessor implements SpanProcessor {
|
|
5
|
+
private _spanAttributes;
|
|
6
|
+
constructor(spanAttributes?: Record<string, SignalAttributeValue | (() => SignalAttributeValue)>);
|
|
7
|
+
forceFlush(): Promise<void>;
|
|
8
|
+
onStart(span: Span, _context: Context): void;
|
|
9
|
+
onEnd(_span: ReadableSpan): void;
|
|
10
|
+
shutdown(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class EnrichSpanProcessor {
|
|
2
|
+
_spanAttributes;
|
|
3
|
+
constructor(spanAttributes) {
|
|
4
|
+
this._spanAttributes = spanAttributes;
|
|
5
|
+
}
|
|
6
|
+
forceFlush() {
|
|
7
|
+
return Promise.resolve();
|
|
8
|
+
}
|
|
9
|
+
onStart(span, _context) {
|
|
10
|
+
if (this._spanAttributes != undefined) {
|
|
11
|
+
for (const [key, value] of Object.entries(this._spanAttributes)) {
|
|
12
|
+
span.setAttribute(key, typeof value === "function" ? value() : value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
onEnd(_span) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
shutdown() {
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getActiveSpan(): import("@opentelemetry/api").Span | undefined;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Attributes, Context, Link, SpanKind } from "@opentelemetry/api";
|
|
2
2
|
import { Sampler, SamplingResult } from "@opentelemetry/sdk-trace-base";
|
|
3
3
|
import { SamplerCondition } from "./index.js";
|
|
4
4
|
export declare class UrlSampler implements Sampler {
|
|
5
5
|
private _samplerCondition;
|
|
6
|
-
|
|
6
|
+
private _nextSampler;
|
|
7
|
+
constructor(samplerCondition: SamplerCondition[] | undefined, nextSampler: Sampler);
|
|
7
8
|
shouldSample(_context: Context, traceId: string, _spanName: string, _spanKind: SpanKind, attributes: Attributes, _links: Link[]): SamplingResult;
|
|
8
9
|
toString(): string;
|
|
9
10
|
}
|
package/dist/lib/url-sampler.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { isValidTraceId, } from "@opentelemetry/api";
|
|
2
1
|
import { SamplingDecision, } from "@opentelemetry/sdk-trace-base";
|
|
3
2
|
export class UrlSampler {
|
|
4
3
|
_samplerCondition;
|
|
5
|
-
|
|
4
|
+
_nextSampler;
|
|
5
|
+
constructor(samplerCondition = [], nextSampler) {
|
|
6
6
|
this._samplerCondition = samplerCondition;
|
|
7
|
+
this._nextSampler = nextSampler;
|
|
7
8
|
}
|
|
8
9
|
shouldSample(_context, traceId, _spanName, _spanKind, attributes, _links) {
|
|
9
10
|
const url = attributes["http.target"]?.toString();
|
|
@@ -16,13 +17,9 @@ export class UrlSampler {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
return
|
|
20
|
-
decision: isValidTraceId(traceId)
|
|
21
|
-
? SamplingDecision.RECORD_AND_SAMPLED
|
|
22
|
-
: SamplingDecision.NOT_RECORD,
|
|
23
|
-
};
|
|
20
|
+
return this._nextSampler.shouldSample(_context, traceId, _spanName, _spanKind, attributes, _links);
|
|
24
21
|
}
|
|
25
22
|
toString() {
|
|
26
|
-
|
|
23
|
+
return "UrlSampler";
|
|
27
24
|
}
|
|
28
25
|
}
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { BatchLogRecordProcessor, SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
1
2
|
import { SDKCollectorMode } from "./index.js";
|
|
2
|
-
import {
|
|
3
|
-
export declare const LogRecordProcessorMap: Record<SDKCollectorMode, typeof
|
|
3
|
+
import { tracing } from "@opentelemetry/sdk-node";
|
|
4
|
+
export declare const LogRecordProcessorMap: Record<SDKCollectorMode, typeof SimpleLogRecordProcessor | typeof BatchLogRecordProcessor>;
|
|
5
|
+
export declare const SpanProcessorMap: Record<SDKCollectorMode, typeof tracing.SimpleSpanProcessor | typeof tracing.BatchSpanProcessor>;
|
package/dist/lib/utils.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BatchLogRecordProcessor, SimpleLogRecordProcessor, } from "@opentelemetry/sdk-logs";
|
|
2
|
+
import { tracing } from "@opentelemetry/sdk-node";
|
|
2
3
|
export const LogRecordProcessorMap = {
|
|
3
|
-
single:
|
|
4
|
-
batch:
|
|
4
|
+
single: SimpleLogRecordProcessor,
|
|
5
|
+
batch: BatchLogRecordProcessor,
|
|
6
|
+
};
|
|
7
|
+
export const SpanProcessorMap = {
|
|
8
|
+
single: tracing.SimpleSpanProcessor,
|
|
9
|
+
batch: tracing.BatchSpanProcessor,
|
|
5
10
|
};
|
package/dist/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ogcio/o11y-sdk-node",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.7",
|
|
4
4
|
"description": "Opentelemetry standard instrumentation SDK for NodeJS based project",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
9
9
|
"test": "vitest",
|
|
10
|
-
"prepublishOnly": "pnpm i && pnpm build"
|
|
10
|
+
"prepublishOnly": "pnpm i && pnpm build",
|
|
11
|
+
"test:unit": "vitest --project unit",
|
|
12
|
+
"test:integration": "pnpm --filter @ogcio/o11y run prepare:integration && vitest --project integration",
|
|
13
|
+
"test:integration:dryrun": "vitest --project integration"
|
|
11
14
|
},
|
|
12
15
|
"exports": {
|
|
13
16
|
".": "./dist/index.js",
|
|
@@ -27,23 +30,24 @@
|
|
|
27
30
|
"@opentelemetry/api": "^1.9.0",
|
|
28
31
|
"@opentelemetry/auto-instrumentations-node": "^0.56.0",
|
|
29
32
|
"@opentelemetry/core": "1.30.1",
|
|
30
|
-
"@opentelemetry/exporter-logs-otlp-grpc": "^0.57.
|
|
31
|
-
"@opentelemetry/exporter-logs-otlp-http": "^0.57.
|
|
32
|
-
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.57.
|
|
33
|
-
"@opentelemetry/exporter-metrics-otlp-http": "^0.57.
|
|
34
|
-
"@opentelemetry/exporter-trace-otlp-grpc": "^0.57.
|
|
35
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.57.
|
|
36
|
-
"@opentelemetry/instrumentation": "^0.57.
|
|
37
|
-
"@opentelemetry/otlp-exporter-base": "^0.57.
|
|
33
|
+
"@opentelemetry/exporter-logs-otlp-grpc": "^0.57.2",
|
|
34
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.57.2",
|
|
35
|
+
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.57.2",
|
|
36
|
+
"@opentelemetry/exporter-metrics-otlp-http": "^0.57.2",
|
|
37
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.57.2",
|
|
38
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.57.2",
|
|
39
|
+
"@opentelemetry/instrumentation": "^0.57.2",
|
|
40
|
+
"@opentelemetry/otlp-exporter-base": "^0.57.2",
|
|
41
|
+
"@opentelemetry/sdk-logs": "^0.57.2",
|
|
38
42
|
"@opentelemetry/sdk-metrics": "^1.30.1",
|
|
39
|
-
"@opentelemetry/sdk-node": "^0.57.
|
|
43
|
+
"@opentelemetry/sdk-node": "^0.57.2",
|
|
40
44
|
"@opentelemetry/sdk-trace-base": "^1.30.1"
|
|
41
45
|
},
|
|
42
46
|
"devDependencies": {
|
|
43
|
-
"@types/node": "^22.
|
|
44
|
-
"@vitest/coverage-v8": "^3.0.
|
|
47
|
+
"@types/node": "^22.13.4",
|
|
48
|
+
"@vitest/coverage-v8": "^3.0.5",
|
|
45
49
|
"tsx": "^4.19.2",
|
|
46
50
|
"typescript": "^5.7.3",
|
|
47
|
-
"vitest": "^3.0.
|
|
51
|
+
"vitest": "^3.0.5"
|
|
48
52
|
}
|
|
49
53
|
}
|
package/dist/vitest.config.js
CHANGED
|
@@ -3,7 +3,6 @@ export default defineConfig({
|
|
|
3
3
|
test: {
|
|
4
4
|
globals: true,
|
|
5
5
|
watch: false,
|
|
6
|
-
include: ["**/test/*.test.ts", "**/test/integration/*.test.ts"],
|
|
7
6
|
exclude: ["**/fixtures/**", "**/dist/**"],
|
|
8
7
|
poolOptions: {
|
|
9
8
|
threads: {
|
|
@@ -21,5 +20,20 @@ export default defineConfig({
|
|
|
21
20
|
},
|
|
22
21
|
reporters: ["default", ["junit", { outputFile: "test-report.xml" }]],
|
|
23
22
|
environment: "node",
|
|
23
|
+
pool: "threads",
|
|
24
|
+
workspace: [
|
|
25
|
+
{
|
|
26
|
+
test: {
|
|
27
|
+
include: ["**/test/*.test.ts"],
|
|
28
|
+
name: "unit",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
test: {
|
|
33
|
+
include: ["**/test/integration/*.test.ts"],
|
|
34
|
+
name: "integration",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
24
38
|
},
|
|
25
39
|
});
|
package/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { NodeSDK } from "@opentelemetry/sdk-node";
|
|
2
|
-
import type { NodeSDKConfig } from "./lib/index.js";
|
|
3
2
|
import buildNodeInstrumentation from "./lib/instrumentation.node.js";
|
|
4
3
|
|
|
5
4
|
export type * from "./lib/index.js";
|
|
6
|
-
export type {
|
|
5
|
+
export type { NodeSDK };
|
|
7
6
|
export { buildNodeInstrumentation as instrumentNode };
|
|
8
7
|
|
|
9
8
|
export * from "./lib/metrics.js";
|
|
9
|
+
export * from "./lib/traces.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConsoleLogRecordExporter,
|
|
3
|
+
SimpleLogRecordProcessor,
|
|
4
|
+
} from "@opentelemetry/sdk-logs";
|
|
5
|
+
import { metrics } from "@opentelemetry/sdk-node";
|
|
6
|
+
import {
|
|
7
|
+
ConsoleSpanExporter,
|
|
8
|
+
SimpleSpanProcessor,
|
|
9
|
+
} from "@opentelemetry/sdk-trace-base";
|
|
10
|
+
import { NodeSDKConfig } from "../index.js";
|
|
11
|
+
import { Exporters } from "../options.js";
|
|
12
|
+
import { EnrichSpanProcessor } from "../processor/enrich-span-processor.js";
|
|
13
|
+
|
|
14
|
+
export default function buildConsoleExporters(
|
|
15
|
+
config: NodeSDKConfig,
|
|
16
|
+
): Exporters {
|
|
17
|
+
return {
|
|
18
|
+
spans: [
|
|
19
|
+
new SimpleSpanProcessor(new ConsoleSpanExporter()),
|
|
20
|
+
new EnrichSpanProcessor(config.spanAttributes),
|
|
21
|
+
],
|
|
22
|
+
metrics: new metrics.PeriodicExportingMetricReader({
|
|
23
|
+
exporter: new metrics.ConsoleMetricExporter(),
|
|
24
|
+
}),
|
|
25
|
+
logs: [new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import type { NodeSDKConfig } from "./index.js";
|
|
2
|
-
import type { Exporters } from "./options.js";
|
|
3
|
-
import { LogRecordProcessorMap } from "./utils.js";
|
|
4
1
|
import { metrics } from "@opentelemetry/sdk-node";
|
|
5
2
|
import { CompressionAlgorithm } from "@opentelemetry/otlp-exporter-base";
|
|
6
3
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-grpc";
|
|
7
4
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-grpc";
|
|
8
5
|
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-grpc";
|
|
6
|
+
import { NodeSDKConfig } from "../index.js";
|
|
7
|
+
import { Exporters } from "../options.js";
|
|
8
|
+
import { LogRecordProcessorMap, SpanProcessorMap } from "../utils.js";
|
|
9
|
+
import { EnrichSpanProcessor } from "../processor/enrich-span-processor.js";
|
|
9
10
|
|
|
10
11
|
export default function buildGrpcExporters(config: NodeSDKConfig): Exporters {
|
|
11
12
|
return {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
spans: [
|
|
14
|
+
new SpanProcessorMap[config.collectorMode ?? "batch"](
|
|
15
|
+
new OTLPTraceExporter({
|
|
16
|
+
url: `${config.collectorUrl}`,
|
|
17
|
+
compression: CompressionAlgorithm.GZIP,
|
|
18
|
+
}),
|
|
19
|
+
),
|
|
20
|
+
new EnrichSpanProcessor(config.spanAttributes),
|
|
21
|
+
],
|
|
16
22
|
metrics: new metrics.PeriodicExportingMetricReader({
|
|
17
23
|
exporter: new OTLPMetricExporter({
|
|
18
24
|
url: `${config.collectorUrl}`,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { NodeSDKConfig } from "./index.js";
|
|
2
|
-
import type { Exporters } from "./options.js";
|
|
3
|
-
import { LogRecordProcessorMap } from "./utils.js";
|
|
4
1
|
import { metrics } from "@opentelemetry/sdk-node";
|
|
5
2
|
import { CompressionAlgorithm } from "@opentelemetry/otlp-exporter-base";
|
|
6
3
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
7
4
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
8
5
|
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
6
|
+
import { LogRecordProcessorMap, SpanProcessorMap } from "../utils.js";
|
|
7
|
+
import { EnrichSpanProcessor } from "../processor/enrich-span-processor.js";
|
|
8
|
+
import { Exporters } from "../options.js";
|
|
9
|
+
import { NodeSDKConfig } from "../index.js";
|
|
9
10
|
|
|
10
11
|
export default function buildHttpExporters(config: NodeSDKConfig): Exporters {
|
|
11
12
|
if (config.collectorUrl.endsWith("/")) {
|
|
@@ -13,10 +14,15 @@ export default function buildHttpExporters(config: NodeSDKConfig): Exporters {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
return {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
spans: [
|
|
18
|
+
new SpanProcessorMap[config.collectorMode ?? "batch"](
|
|
19
|
+
new OTLPTraceExporter({
|
|
20
|
+
url: `${config.collectorUrl}/v1/traces`,
|
|
21
|
+
compression: CompressionAlgorithm.GZIP,
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
new EnrichSpanProcessor(config.spanAttributes),
|
|
25
|
+
],
|
|
20
26
|
metrics: new metrics.PeriodicExportingMetricReader({
|
|
21
27
|
exporter: new OTLPMetricExporter({
|
|
22
28
|
url: `${config.collectorUrl}/v1/metrics`,
|