Skip to content

Commit 6691fe2

Browse files
fix/transport cleanup, new stacktrace-parser version, fixes for otel mapper
1 parent 1d3e288 commit 6691fe2

6 files changed

Lines changed: 69 additions & 47 deletions

File tree

packages/traceo-sdk-node-core/src/transport.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -105,41 +105,41 @@ const requestOptions = (url: string, method: RequestType): http.RequestOptions =
105105
};
106106
};
107107

108-
const requestHeaders = (method: RequestType) => {
109-
const headers = getGlobalTraceo().headers;
110-
111-
if (method !== "POST") return headers;
112-
return {
113-
headers: {
114-
"Content-Type": "application/json",
115-
...headers
116-
}
117-
};
118-
};
119-
120-
/**
121-
* Make http/s request to Traceo platoform.
122-
*
123-
* Default request method is POST, in this case in hedaers is passed "Content-Type": "application/json".
124-
* URL is concatenation of passed host to client and pathanme to this method.
125-
* Use callback/onError callbacks to handle action after operation.
126-
*/
127-
const request = ({ url, method = "POST", body, onError, callback }: RequestOptionsType) => {
128-
const options = {
129-
...requestHeaders(method),
130-
...requestOptions(url, method)
131-
};
132-
133-
const httpModule = requestModule();
134-
135-
const request = httpModule.request(options, callback);
136-
request.on("error", () => onError);
137-
138-
requestWriteBody(method, request, body);
139-
140-
request.end();
141-
};
142-
143-
export const transport = {
144-
request
145-
};
108+
// const requestHeaders = (method: RequestType) => {
109+
// const headers = getGlobalTraceo().headers;
110+
111+
// if (method !== "POST") return headers;
112+
// return {
113+
// headers: {
114+
// "Content-Type": "application/json",
115+
// ...headers
116+
// }
117+
// };
118+
// };
119+
120+
// /**
121+
// * Make http/s request to Traceo platoform.
122+
// *
123+
// * Default request method is POST, in this case in hedaers is passed "Content-Type": "application/json".
124+
// * URL is concatenation of passed host to client and pathanme to this method.
125+
// * Use callback/onError callbacks to handle action after operation.
126+
// */
127+
// const request = ({ url, method = "POST", body, onError, callback }: RequestOptionsType) => {
128+
// const options = {
129+
// ...requestHeaders(method),
130+
// ...requestOptions(url, method)
131+
// };
132+
133+
// const httpModule = requestModule();
134+
135+
// const request = httpModule.request(options, callback);
136+
// request.on("error", () => onError);
137+
138+
// requestWriteBody(method, request, body);
139+
140+
// request.end();
141+
// };
142+
143+
// export const transport = {
144+
// request
145+
// };

packages/traceo-sdk-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"test:watch": "jest --watch --notify"
3434
},
3535
"dependencies": {
36-
"stacktrace-parser-node": "^1.1.3",
36+
"stacktrace-parser-node": "^1.1.5",
3737
"@traceo-sdk/node-core": "0.33.1",
3838
"os": "^0.1.2"
3939
},

packages/traceo-sdk-node/src/metrics/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ import { EventLoopMetrics } from "./default/event-loop";
33
import { HeapMetrics } from "./default/heap";
44
import { MemoryUsageMetrics } from "./default/memory-usage";
55
import {
6-
transport,
6+
HttpClient,
77
CAPTURE_ENDPOINT,
88
utils,
9-
MetricType,
10-
InstrumentType,
11-
ValueType,
129
INodeClient,
13-
DataPointType,
1410
TraceoMetricType,
1511
TraceoMetric
1612
} from "@traceo-sdk/node-core";
@@ -64,7 +60,11 @@ export class MetricsRunner {
6460

6561
const metrics: TraceoMetric[] = [...cpuUsage, ...eventLoop, ...heap, ...memory, ...this.loadAvg];
6662

67-
transport.request({
63+
if (metrics.length === 0) {
64+
return;
65+
}
66+
67+
HttpClient.request({
6868
url: CAPTURE_ENDPOINT.METRICS,
6969
body: metrics,
7070
onError: (error: Error) => {

packages/traceo-sdk-opentelemetry/src/exporters/metricsExporter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export class TraceoMetricExporter extends OTLPMetricExporter {
3434
}
3535

3636
const payload: TraceoMetric[] = OtelMapper.mapMetrics(metrics);
37+
if (payload.length === 0) {
38+
return;
39+
}
40+
3741
HttpClient.request({
3842
body: payload,
3943
url: CAPTURE_ENDPOINT.METRICS,

packages/traceo-sdk-opentelemetry/src/exporters/otelMapper.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class OtelMapper {
5151
return otelSpans.map((otel) => ({
5252
name: otel.name,
5353
kind: this.getSpanKind(otel.kind),
54-
status: otel.status.code.toString(),
54+
status: this.getSpanStatus(otel.status.code),
5555
statusMessage: otel.status.message,
5656
traceId: otel.spanContext().traceId,
5757
spanId: otel.spanContext().spanId,
@@ -77,10 +77,24 @@ export class OtelMapper {
7777
case SpanKind.CONSUMER:
7878
return "CONSUMER";
7979
default:
80-
return "";
80+
return "N/A";
8181
}
8282
}
8383

84+
private static getSpanStatus(status: SpanStatusCode): string {
85+
if (!status) {
86+
return "Unset";
87+
}
88+
89+
if (status === SpanStatusCode.ERROR) {
90+
return "Error";
91+
} else if (status === SpanStatusCode.OK) {
92+
return "OK";
93+
}
94+
95+
return "Unset";
96+
}
97+
8498
private static getEpochNanos(time: HrTime): number {
8599
return time[0] + time[1] / 1e9;
86100
}

packages/traceo-sdk-opentelemetry/src/exporters/tracingExporter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export class TraceoTracingExporter extends OTLPTraceExporter {
2929
}
3030

3131
const payload: TraceoSpan[] = OtelMapper.mapSpans(items);
32+
if (payload.length === 0) {
33+
return;
34+
}
35+
3236
HttpClient.request({
3337
body: payload,
3438
url: CAPTURE_ENDPOINT.TRACING,

0 commit comments

Comments
 (0)