-
Notifications
You must be signed in to change notification settings - Fork 348
[SVLS-7305] Instrument Azure Event Hubs #6559
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
51 commits
Select commit
Hold shift + click to select a range
767526c
initial
jcstorms1 e0a0dd2
wrap eventhub methods
jcstorms1 3e57935
trace eventhub in azure function
jcstorms1 b8eaf5d
add span attributes for event hub
jcstorms1 3a7230d
update hooks
jcstorms1 a15e8c7
add list and single message support
jcstorms1 dbdfa32
refactor
jcstorms1 e7c4ac1
use this to get the config
jcstorms1 40e6353
refactor and add span links
jcstorms1 40bf893
add buffered event queues
jcstorms1 09e06a3
initial eventhubs test passing
jcstorms1 d796013
add event hubs producer tests
jcstorms1 4d4524b
break apart tests
jcstorms1 975ef63
initial eventhub function test
jcstorms1 b085289
use batches span context array
jcstorms1 96fc0db
finalize tests
jcstorms1 c5bcc4e
uncomment tests
jcstorms1 0d5160f
Merge branch 'master' into storms/instrument-event-hub
jcstorms1 85f50e2
update docker compose
jcstorms1 0cb912f
remove env file and hardcode volume
jcstorms1 a9b858f
tests
jcstorms1 9354e55
try workaround
jcstorms1 94ee7bd
typo
jcstorms1 1c61388
fix docker cp command
jcstorms1 4d897c9
update test package.json
jcstorms1 7867061
test reordering service
jcstorms1 8e5ca50
update eventhubs service
jcstorms1 07f441d
missing import
jcstorms1 4484701
update dd-trace dependancies
jcstorms1 872c5c0
refactor tests
jcstorms1 7c54c68
update ports
jcstorms1 b58dfd2
reorder services
jcstorms1 2f886fa
start with azure edge
jcstorms1 cdfb243
add docker cp to functions for config
jcstorms1 31bf564
try new action
jcstorms1 c4e4859
typo
jcstorms1 18974d7
retry test
jcstorms1 63175db
try using service id
jcstorms1 8a10b57
update service bus version
jcstorms1 c31b0b6
remove localhost reference
jcstorms1 7181770
pin core tools version for fx
jcstorms1 ee296b9
update path for http
jcstorms1 a2de912
reset func core tool version
jcstorms1 261c11e
simplify github workflow
jcstorms1 d4f5721
move tests to serverless action
jcstorms1 b41b693
update node version used
jcstorms1 bfd438f
fix messaging system in fx
jcstorms1 15ed318
update test
jcstorms1 c50259a
fix tests and add check for empty events
jcstorms1 d5814ee
fix index in eventhub test
jcstorms1 71e3cfc
move test to appropriate plugin
jcstorms1 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,30 @@ jobs: | |
with: | ||
suffix: plugins-${{ github.job }}-${{ matrix.node-version }} | ||
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1 | ||
|
||
azure-event-hubs: | ||
runs-on: ubuntu-latest | ||
services: | ||
azurite: | ||
image: mcr.microsoft.com/azure-storage/azurite:3.35.0 | ||
ports: | ||
- "127.0.0.1:10000:10000" | ||
- "127.0.0.1:10001:10001" | ||
- "127.0.0.1:10002:10002" | ||
azureeventhubsemulator: | ||
image: mcr.microsoft.com/azure-messaging/eventhubs-emulator:2.1.0 | ||
ports: | ||
- "127.0.0.1:5673:5672" | ||
- "127.0.0.1:9092:9092" | ||
env: | ||
BLOB_SERVER: azurite | ||
METADATA_SERVER: azurite | ||
ACCEPT_EULA: "Y" | ||
env: | ||
PLUGINS: azure-event-hubs | ||
SERVICES: azurite,azureeventhubsemulator | ||
steps: | ||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
- uses: ./.github/actions/plugins/test | ||
azure-functions: | ||
runs-on: ubuntu-latest | ||
services: | ||
|
@@ -97,6 +120,15 @@ jobs: | |
- "127.0.0.1:10000:10000" | ||
- "127.0.0.1:10001:10001" | ||
- "127.0.0.1:10002:10002" | ||
azureeventhubsemulator: | ||
image: mcr.microsoft.com/azure-messaging/eventhubs-emulator:2.1.0 | ||
ports: | ||
- "127.0.0.1:5673:5672" | ||
- "127.0.0.1:9092:9092" | ||
env: | ||
BLOB_SERVER: azurite | ||
METADATA_SERVER: azurite | ||
ACCEPT_EULA: "Y" | ||
azureservicebusemulator: | ||
image: mcr.microsoft.com/azure-messaging/servicebus-emulator:1.1.2 | ||
ports: | ||
|
@@ -115,10 +147,16 @@ jobs: | |
MSSQL_SA_PASSWORD: "Localtestpass1!" | ||
env: | ||
PLUGINS: azure-functions | ||
SERVICES: azureservicebusemulator,azuresqledge | ||
SERVICES: azureservicebusemulator,azuresqledge,azurite,azureeventhubsemulator | ||
steps: | ||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
- uses: ./.github/actions/node/active-lts | ||
- run: | | ||
docker cp \ | ||
${{ github.workspace }}/packages/datadog-plugin-azure-functions/test/fixtures/eventhub-emulator-config.json \ | ||
${{ job.services.azureeventhubsemulator.id }}:/Eventhubs_Emulator/ConfigFiles/Config.json | ||
- run : | | ||
docker restart ${{ job.services.azureeventhubsemulator.id }} | ||
- uses: ./.github/actions/node/newest-maintenance-lts | ||
- uses: ./.github/actions/install | ||
- run: npm install -g [email protected] | ||
- run: echo "$(dirname $(which func))" >> $GITHUB_PATH | ||
|
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,37 @@ | ||
'use strict' | ||
|
||
const { | ||
addHook | ||
} = require('./helpers/instrument') | ||
const shimmer = require('../../datadog-shimmer') | ||
const dc = require('dc-polyfill') | ||
|
||
const producerCh = dc.tracingChannel('apm:azure-event-hubs:send') | ||
|
||
addHook({ | ||
name: '@azure/event-hubs', | ||
versions: ['>=6.0.0'] | ||
}, obj => { | ||
const EventHubProducerClient = obj.EventHubProducerClient | ||
shimmer.wrap(EventHubProducerClient.prototype, 'createBatch', | ||
createBatch => async function () { | ||
const batch = await createBatch.apply(this, arguments) | ||
shimmer.wrap(batch, 'tryAdd', | ||
tryAdd => function (eventData) { | ||
const config = this._context.config | ||
const functionName = tryAdd.name | ||
return producerCh.tracePromise( | ||
tryAdd, | ||
{ functionName, eventData, batch: this, config }, | ||
this, ...arguments) | ||
}) | ||
return batch | ||
}) | ||
shimmer.wrap(EventHubProducerClient.prototype, 'sendBatch', | ||
sendBatch => function (eventData) { | ||
const config = this._context.config | ||
const functionName = sendBatch.name | ||
return producerCh.tracePromise(sendBatch, { functionName, eventData, config }, this, ...arguments) | ||
}) | ||
return obj | ||
}) |
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,15 @@ | ||
'use strict' | ||
|
||
const ProducerPlugin = require('./producer') | ||
const CompositePlugin = require('../../dd-trace/src/plugins/composite') | ||
|
||
class AzureEventHubsPlugin extends CompositePlugin { | ||
static get id () { return 'azure-event-hubs' } | ||
static get plugins () { | ||
return { | ||
producer: ProducerPlugin | ||
} | ||
} | ||
} | ||
|
||
module.exports = AzureEventHubsPlugin |
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,82 @@ | ||
'use strict' | ||
|
||
const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper') | ||
const ProducerPlugin = require('../../dd-trace/src/plugins/producer') | ||
|
||
class AzureEventHubsProducerPlugin extends ProducerPlugin { | ||
static get id () { return 'azure-event-hubs' } | ||
static get operation () { return 'send' } | ||
static get prefix () { return 'tracing:apm:azure-event-hubs:send' } | ||
|
||
bindStart (ctx) { | ||
// we do not want to make these spans when batch linking is disabled. | ||
if (!batchLinksAreEnabled() && ctx.functionName === 'tryAdd') { | ||
return ctx.currentStore | ||
} | ||
|
||
const qualifiedNamespace = ctx.config.endpoint.replace('sb://', '').replace('/', '') | ||
const entityPath = ctx.config.entityPath | ||
const span = this.startSpan({ | ||
resource: entityPath, | ||
type: 'messaging', | ||
meta: { | ||
component: 'azure-event-hubs', | ||
'messaging.system': 'eventhubs', | ||
'messaging.destination.name': entityPath, | ||
'network.destination.name': qualifiedNamespace, | ||
} | ||
}, ctx) | ||
|
||
if (ctx.functionName === 'tryAdd') { | ||
span._spanContext._name = 'azure.eventhubs.create' | ||
jcstorms1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
span.setTag('messaging.operation', 'create') | ||
|
||
if (ctx.eventData.messageID !== undefined) { | ||
span.setTag('message.id', ctx.eventData.messageID) | ||
} | ||
|
||
if (batchLinksAreEnabled()) { | ||
ctx.batch._spanContexts.push(span.context()) | ||
injectTraceContext(this.tracer, span, ctx.eventData) | ||
} | ||
} | ||
|
||
if (ctx.functionName === 'sendBatch') { | ||
const eventData = ctx.eventData | ||
const eventDataLength = eventData.length || eventData._context.connection._eventsCount | ||
span.setTag('messaging.operation', 'send') | ||
span.setTag('messaging.batch.message_count', eventDataLength) | ||
|
||
if (eventData.constructor.name !== 'EventDataBatchImpl' && Array.isArray(eventData)) { | ||
eventData.forEach(event => { | ||
injectTraceContext(this.tracer, span, event) | ||
jcstorms1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
} else { | ||
if (batchLinksAreEnabled()) { | ||
eventData._spanContexts.forEach(spanContext => { | ||
span.addLink(spanContext) | ||
}) | ||
} | ||
} | ||
} | ||
return ctx.currentStore | ||
} | ||
|
||
asyncEnd (ctx) { | ||
super.finish() | ||
} | ||
} | ||
|
||
function injectTraceContext (tracer, span, event) { | ||
if (!event.properties) { | ||
event.properties = {} | ||
} | ||
tracer.inject(span, 'text_map', event.properties) | ||
} | ||
|
||
function batchLinksAreEnabled () { | ||
const eh = getEnvironmentVariable('DD_TRACE_AZURE_EVENTHUBS_BATCH_LINKS_ENABLED') | ||
return eh !== 'false' | ||
} | ||
|
||
module.exports = AzureEventHubsProducerPlugin |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a config file for the Event Hubs emulator, but in github workflows we can't mount the file. The workaround is to use
docker cp
and restart the service. https://github.com/orgs/community/discussions/42127#discussioncomment-7591609