-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added segment synthesis for otel producer spans
- Loading branch information
Showing
9 changed files
with
142 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,29 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const { | ||
SEMATTRS_MESSAGING_SYSTEM, | ||
SEMATTRS_MESSAGING_DESTINATION, | ||
SEMATTRS_MESSAGING_DESTINATION_KIND | ||
} = require('@opentelemetry/semantic-conventions') | ||
|
||
module.exports = function createProducerSegment(agent, otelSpan) { | ||
const context = agent.tracer.getContext() | ||
const name = setName(otelSpan) | ||
const segment = agent.tracer.createSegment({ | ||
name, | ||
parent: context.segment, | ||
transaction: context.transaction | ||
}) | ||
return { segment, transaction: context.transaction } | ||
} | ||
|
||
function setName(otelSpan) { | ||
const system = otelSpan.attributes[SEMATTRS_MESSAGING_SYSTEM] || 'Unknown' | ||
const destKind = otelSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] || 'Unknown' | ||
const destination = otelSpan.attributes[SEMATTRS_MESSAGING_DESTINATION] || 'Unknown' | ||
return `MessageBroker/${system}/${destKind}/Produce/Named/${destination}` | ||
} |
This file contains 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 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,35 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const { | ||
MessagingDestinationKindValues, | ||
SEMATTRS_MESSAGING_SYSTEM, | ||
SEMATTRS_MESSAGING_DESTINATION, | ||
SEMATTRS_MESSAGING_DESTINATION_KIND | ||
} = require('@opentelemetry/semantic-conventions') | ||
const { SpanKind } = require('@opentelemetry/api') | ||
const createSpan = require('./span') | ||
|
||
function createTopicProducerSpan({ parentId, tracer, tx, name = 'test-span' }) { | ||
const span = createSpan({ name, kind: SpanKind.PRODUCER, parentId, tracer, tx }) | ||
span.setAttribute(SEMATTRS_MESSAGING_SYSTEM, 'messaging-lib') | ||
span.setAttribute(SEMATTRS_MESSAGING_DESTINATION_KIND, MessagingDestinationKindValues.TOPIC) | ||
span.setAttribute(SEMATTRS_MESSAGING_DESTINATION, 'test-topic') | ||
return span | ||
} | ||
|
||
function createQueueProducerSpan({ parentId, tracer, tx, name = 'test-span' }) { | ||
const span = createSpan({ name, kind: SpanKind.PRODUCER, parentId, tracer, tx }) | ||
span.setAttribute(SEMATTRS_MESSAGING_SYSTEM, 'messaging-lib') | ||
span.setAttribute(SEMATTRS_MESSAGING_DESTINATION_KIND, MessagingDestinationKindValues.QUEUE) | ||
span.setAttribute(SEMATTRS_MESSAGING_DESTINATION, 'test-queue') | ||
return span | ||
} | ||
|
||
module.exports = { | ||
createQueueProducerSpan, | ||
createTopicProducerSpan | ||
} |
This file contains 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 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