Skip to content

Commit 5cacc81

Browse files
feat/otel tracing exporter
1 parent be75e97 commit 5cacc81

4 files changed

Lines changed: 62 additions & 10 deletions

File tree

packages/opentelemetry-node/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
},
2626
"dependencies": {
2727
"@opentelemetry/api": "^1.4.1",
28-
"@opentelemetry/exporter-metrics-otlp-proto": "^0.38.0",
28+
"@opentelemetry/exporter-metrics-otlp-http": "^0.38.0",
29+
"@opentelemetry/exporter-trace-otlp-http": "^0.39.1",
2930
"@traceo-sdk/node-core": "0.32.2",
3031
"os": "^0.1.2",
3132
"stacktrace-parser-node": "^1.1.3"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export { TraceoOTLPMetricExporter } from "./otel-metrics-exporter";
1+
export { TraceoMetricExporter } from "./metrics-exporter";
2+
export { TraceoTracingExporter } from "./tracing-exporter";

packages/opentelemetry-node/src/exporters/otel-metrics-exporter.ts renamed to packages/opentelemetry-node/src/exporters/metrics-exporter.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-proto";
1+
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
22
import {
33
CAPTURE_ENDPOINT,
44
MetricData,
@@ -9,11 +9,11 @@ import {
99
ExportResult,
1010
ExportResultCode,
1111
ResourceMetrics,
12-
INodeClient
12+
INodeClient,
13+
utils
1314
} from "@traceo-sdk/node-core";
14-
import { getGlobalTraceo } from "@traceo-sdk/node-core/dist/utils";
1515

16-
export class TraceoOTLPMetricExporter extends OTLPMetricExporter {
16+
export class TraceoMetricExporter extends OTLPMetricExporter {
1717
private client: INodeClient;
1818

1919
constructor(config?: OTLPExporterNodeConfigBase) {
@@ -22,7 +22,7 @@ export class TraceoOTLPMetricExporter extends OTLPMetricExporter {
2222
temporalityPreference: AggregationTemporality.DELTA
2323
});
2424

25-
this.client = getGlobalTraceo();
25+
this.client = utils.getGlobalTraceo();
2626
}
2727

2828
public export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void {
@@ -40,14 +40,17 @@ export class TraceoOTLPMetricExporter extends OTLPMetricExporter {
4040
body: flatMetrics,
4141
url: CAPTURE_ENDPOINT.METRICS,
4242
method: "POST",
43+
callback: () => {
44+
resultCallback({ code: ExportResultCode.SUCCESS });
45+
},
4346
onError: (error: Error) => {
4447
console.error(
45-
`Traceo Error. Something went wrong while sending new Metrics to Traceo. Please report this issue.`
48+
`Traceo Error. Something went wrong while sending new metrics to Traceo. Please report this issue.`
4649
);
4750
console.error(`Caused by: ${error.message}`);
51+
52+
resultCallback({ code: ExportResultCode.FAILED });
4853
}
4954
});
50-
51-
resultCallback({ code: ExportResultCode.SUCCESS });
5255
}
5356
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
2+
import {
3+
INodeClient,
4+
utils,
5+
transport,
6+
CAPTURE_ENDPOINT,
7+
ExportResultCode,
8+
ReadableSpan,
9+
ExportResult,
10+
OTLPExporterNodeConfigBase
11+
} from "@traceo-sdk/node-core";
12+
13+
export class TraceoTracingExporter extends OTLPTraceExporter {
14+
private client: INodeClient;
15+
16+
constructor(config: OTLPExporterNodeConfigBase) {
17+
super(config);
18+
19+
this.client = utils.getGlobalTraceo();
20+
}
21+
22+
public export(items: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {
23+
const isOffline = this.client.options.offline;
24+
25+
if (isOffline) {
26+
return;
27+
}
28+
29+
transport.request({
30+
body: items,
31+
url: CAPTURE_ENDPOINT.TRACING,
32+
method: "POST",
33+
callback: () => {
34+
resultCallback({ code: ExportResultCode.SUCCESS });
35+
},
36+
onError: (error: Error) => {
37+
console.error(
38+
`Traceo Error. Something went wrong while sending new Traces to Traceo. Please report this issue.`
39+
);
40+
console.error(`Caused by: ${error.message}`);
41+
42+
resultCallback({ code: ExportResultCode.FAILED });
43+
}
44+
});
45+
46+
}
47+
}

0 commit comments

Comments
 (0)