Skip to content

Commit 209c780

Browse files
committed
refactor(otlp): rely on initialized resource inputs
1 parent 0b90173 commit 209c780

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

packages/dd-trace/src/opentelemetry/metrics/index.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function initializeOpenTelemetryMetrics (config) {
8181
}
8282

8383
/**
84-
* @param {Record<string, unknown>} [tags]
84+
* @param {Record<string, unknown>} tags
8585
* @param {object} [options]
8686
* @param {boolean} [options.reportHostname]
8787
* @param {string} [options.service]
@@ -100,20 +100,18 @@ function buildResourceAttributes (tags, { reportHostname, service, env, serviceV
100100
if (env) attrs['deployment.environment.name'] = env
101101
if (reportHostname) attrs['host.name'] = os.hostname()
102102

103-
if (tags?.['runtime-id']) attrs['datadog.runtime_id'] = tags['runtime-id']
104-
if (tags) {
105-
const tracerTags = []
106-
for (const [key, value] of Object.entries(tags)) {
107-
const valueType = typeof value
108-
const supported = valueType === 'string' || valueType === 'boolean' ||
109-
(valueType === 'number' && Number.isFinite(value))
110-
if (!RESERVED_TRACER_TAGS.has(key) && supported) tracerTags.push(`${key}:${value}`)
111-
}
112-
if (tracerTags.length) attrs['datadog.tracer_tags'] = tracerTags
103+
if (tags['runtime-id']) attrs['datadog.runtime_id'] = tags['runtime-id']
104+
const tracerTags = []
105+
for (const [key, value] of Object.entries(tags)) {
106+
const valueType = typeof value
107+
const supported = valueType === 'string' || valueType === 'boolean' ||
108+
(valueType === 'number' && Number.isFinite(value))
109+
if (!RESERVED_TRACER_TAGS.has(key) && supported) tracerTags.push(`${key}:${value}`)
113110
}
111+
if (tracerTags.length) attrs['datadog.tracer_tags'] = tracerTags
114112
// Mirrors the legacy v0.6/stats ProcessTags shape (buildProcessTags().tagsArray); keep both in sync.
115113
const processTagsArray = processTags.tagsArray
116-
if (processTagsArray?.length) {
114+
if (processTagsArray.length) {
117115
attrs['datadog.process_tags'] = processTagsArray
118116
}
119117
return attrs

packages/dd-trace/test/opentelemetry/metrics/otlp_span_stats_exporter.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const assert = require('node:assert/strict')
44
const http = require('node:http')
5-
const { describe, it, beforeEach, afterEach } = require('mocha')
5+
const { describe, it, before, beforeEach, afterEach } = require('mocha')
66
const sinon = require('sinon')
77

88
require('../../setup/core')
@@ -16,6 +16,8 @@ const processTags = require('../../../src/process-tags')
1616
const RESOURCE_ATTRS = { 'service.name': 'svc' }
1717
const BUCKET_SIZE_NS = 10 * 1e9
1818

19+
before(() => processTags.initialize())
20+
1921
function makeSpan (overrides = {}) {
2022
return {
2123
startTime: 12345 * 1e9,
@@ -91,7 +93,6 @@ describe('buildResourceAttributes', () => {
9193
})
9294

9395
it('includes datadog.process_tags as a single array attribute', () => {
94-
processTags.initialize()
9596
const attrs = buildResourceAttributes({})
9697
assert.ok(Array.isArray(attrs['datadog.process_tags']))
9798
assert.ok(!('datadog.entrypoint.type' in attrs))
@@ -113,6 +114,7 @@ describe('createOtlpSpanStatsExporter', () => {
113114
const exporter = createOtlpSpanStatsExporter({
114115
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: 'http://localhost:4318/v1/metrics',
115116
service: 'svc',
117+
tags: {},
116118
})
117119
assert.ok(exporter instanceof OtlpStatsExporter)
118120
})

0 commit comments

Comments
 (0)