-
Notifications
You must be signed in to change notification settings - Fork 383
feat(process-discovery): include process_tags and container_id in tracer metadata #7816
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
6f67638
feat(process-discovery): include process_tags and container_id in tra…
tlhunter 031416d
fix(crashtracking): skip crashtracker on ARM64 musl to avoid segfault
tlhunter 382f100
fix(process-discovery): simplify processTagsSerialized to use null di…
tlhunter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| 'use strict' | ||
|
|
||
| const assert = require('node:assert/strict') | ||
| const { describe, it, beforeEach, afterEach } = require('mocha') | ||
| const proxyquire = require('proxyquire') | ||
| const sinon = require('sinon') | ||
|
|
||
| describe('tracer_metadata', () => { | ||
| let storeConfig | ||
| let storeMetadataStub | ||
| let TracerMetadataStub | ||
| let processDiscoveryStub | ||
| let libdatadogStub | ||
| let dockerStub | ||
| let processTagsStub | ||
|
|
||
| const baseConfig = { | ||
| tags: { 'runtime-id': 'test-runtime-id' }, | ||
| hostname: 'test-host', | ||
| service: 'test-service', | ||
| env: 'test-env', | ||
| version: '1.0.0', | ||
| propagateProcessTags: { enabled: false }, | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| storeMetadataStub = sinon.stub().returns({ handle: 'mock-handle' }) | ||
| TracerMetadataStub = sinon.stub() | ||
|
|
||
| processDiscoveryStub = { | ||
| TracerMetadata: TracerMetadataStub, | ||
| storeMetadata: storeMetadataStub, | ||
| } | ||
|
|
||
| libdatadogStub = { | ||
| maybeLoad: sinon.stub().withArgs('process-discovery').returns(processDiscoveryStub), | ||
| } | ||
|
|
||
| dockerStub = { containerId: undefined } | ||
| processTagsStub = { serialized: 'tag1:val1,tag2:val2' } | ||
|
|
||
| storeConfig = proxyquire('../src/tracer_metadata', { | ||
| '@datadog/libdatadog': libdatadogStub, | ||
| './exporters/common/docker': dockerStub, | ||
| './process-tags': processTagsStub, | ||
| }) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore() | ||
| }) | ||
|
|
||
| it('calls storeMetadata with correct base fields', () => { | ||
| storeConfig(baseConfig) | ||
|
|
||
| sinon.assert.calledOnce(TracerMetadataStub) | ||
| const args = TracerMetadataStub.firstCall.args | ||
| assert.strictEqual(args[0], 'test-runtime-id') | ||
| assert.strictEqual(args[2], 'test-host') | ||
| assert.strictEqual(args[3], 'test-service') | ||
| assert.strictEqual(args[4], 'test-env') | ||
| assert.strictEqual(args[5], '1.0.0') | ||
|
|
||
| sinon.assert.calledOnce(storeMetadataStub) | ||
| }) | ||
|
|
||
| it('passes null for process_tags when propagateProcessTags is disabled', () => { | ||
| storeConfig({ ...baseConfig, propagateProcessTags: { enabled: false } }) | ||
|
|
||
| const args = TracerMetadataStub.firstCall.args | ||
| assert.strictEqual(args[6], null) | ||
| }) | ||
|
|
||
| it('passes serialized process tags when propagateProcessTags is enabled', () => { | ||
| storeConfig({ ...baseConfig, propagateProcessTags: { enabled: true } }) | ||
|
|
||
| const args = TracerMetadataStub.firstCall.args | ||
| assert.strictEqual(args[6], 'tag1:val1,tag2:val2') | ||
| }) | ||
|
|
||
| it('passes container_id when available', () => { | ||
| dockerStub.containerId = 'abc123container' | ||
|
|
||
| storeConfig(baseConfig) | ||
|
|
||
| const args = TracerMetadataStub.firstCall.args | ||
| assert.strictEqual(args[7], 'abc123container') | ||
| }) | ||
|
|
||
| it('passes null for container_id when not in a container', () => { | ||
| dockerStub.containerId = undefined | ||
|
|
||
| storeConfig(baseConfig) | ||
|
|
||
| const args = TracerMetadataStub.firstCall.args | ||
| assert.strictEqual(args[7], null) | ||
| }) | ||
|
|
||
| it('passes null for service when config.service is falsy', () => { | ||
| storeConfig({ ...baseConfig, service: undefined }) | ||
|
|
||
| const args = TracerMetadataStub.firstCall.args | ||
| assert.strictEqual(args[3], null) | ||
| }) | ||
|
|
||
| it('returns undefined and does not throw when process-discovery is unavailable', () => { | ||
| libdatadogStub.maybeLoad.returns(undefined) | ||
|
|
||
| const result = storeConfig(baseConfig) | ||
| assert.strictEqual(result, undefined) | ||
| }) | ||
|
|
||
| it('returns undefined and does not throw when libdatadog throws', () => { | ||
| const storeConfigWithThrow = proxyquire('../src/tracer_metadata', { | ||
| '@datadog/libdatadog': { maybeLoad: () => { throw new Error('load error') } }, | ||
| './exporters/common/docker': dockerStub, | ||
| './process-tags': processTagsStub, | ||
| }) | ||
|
|
||
| const result = storeConfigWithThrow(baseConfig) | ||
| assert.strictEqual(result, undefined) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.