Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nodejs] modify baggage tests for nodejs + add associated nodejs endpoints #3299

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion manifests/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ tests/:
TestDynamicConfigV1_ServiceTargets: *ref_5_4_0
TestDynamicConfigV2: *ref_4_23_0
test_headers_baggage.py:
Test_Headers_Baggage: missing_feature
Test_Headers_Baggage: v5.25.0
test_otel_api_interoperability.py: missing_feature
test_otel_env_vars.py:
Test_Otel_Env_Vars: v5.11.0 #implemented in v5.11.0, v4.35.0, &v3.56.0
Expand Down
1 change: 0 additions & 1 deletion tests/parametric/test_headers_baggage.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def test_headers_baggage_only_D002(self, test_library):
assert "x-datadog-trace-id" not in headers.keys()
assert "x-datadog-parent-id" not in headers.keys()
assert "baggage" in headers.keys()
assert len(headers.keys()) == 1
assert headers["baggage"] == "foo=bar"

@disable_baggage()
Expand Down
47 changes: 47 additions & 0 deletions utils/build/docker/nodejs/parametric/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const express = require('express');
const app = express();
app.use(express.json());

let dummyIdIncrementer = 10000000

function microLongToHrTime (timestamp) {
if (timestamp === null) {
Expand Down Expand Up @@ -71,6 +72,17 @@ app.post('/trace/span/extract_headers', (req, res) => {
const extracted = tracer.extract('http_headers', linkHeaders);

let extractedSpanID = null;
const dummyTracer = require('dd-trace').init()
const extractPropagator = dummyTracer._tracer._config.tracePropagationStyle.extract

if (extractPropagator.includes('baggage') && extracted && !extracted._spanId && !extracted._traceId) {
// baggage propagation does not require ids so http_headers could contain no ids
// several endpoints in this file rely on having ids so we need to have dummy ids for internal use
extracted._spanId = dummyIdIncrementer
extracted._traceId = dummyIdIncrementer
dummyIdIncrementer += 1
}

if (extracted && extracted._spanId) {
extractedSpanID = extracted.toSpanId();
ddContext[extractedSpanID] = extracted;
Expand Down Expand Up @@ -168,6 +180,41 @@ app.post('/trace/span/error', (req, res) => {
res.json({});
});

app.post('/trace/span/set_baggage', (req, res) => {
const request = req.body;
const span = spans[request.span_id]
span.setBaggageItem(request.key, request.value)
res.json({});
});

app.get('/trace/span/get_baggage', (req, res) => {
const request = req.body;
const span = spans[request.span_id]
const baggage = span.getBaggageItem(request.key)
res.json({ baggage });
});

app.get('/trace/span/get_all_baggage', (req, res) => {
const request = req.body;
const span = spans[request.span_id]
const baggage = span.getAllBaggageItems()
res.json({ baggage: JSON.parse(baggage) });
});

app.post('/trace/span/remove_baggage', (req, res) => {
const request = req.body;
const span = spans[request.span_id]
const baggages = span.removeBaggageItem(request.key)
res.json({});
});

app.post('/trace/span/remove_all_baggage', (req, res) => {
const request = req.body;
const span = spans[request.span_id]
const baggages = span.removeAllBaggageItems()
res.json({});
});

app.post('/trace/otel/start_span', (req, res) => {
const request = req.body;
const otelTracer = tracerProvider.getTracer()
Expand Down
Loading