Skip to content

Commit

Permalink
Merge pull request #234 from dhensby/pulls/trace-context
Browse files Browse the repository at this point in the history
feat: add `traceparent` value to `traceContext`
  • Loading branch information
dhensby authored Sep 10, 2024
2 parents ff75712 + fa06e41 commit f63c897
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/bindings/queue-binding.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// see https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue
import { Binding } from '../types';
import { v4 as uuid } from 'uuid';
import { randomUUID as uuid } from 'crypto';
import { ContextBindings } from '@azure/functions';

export type QueueBindingData = {
Expand Down
4 changes: 2 additions & 2 deletions lib/context-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
HttpResponseFull,
Logger,
} from '@azure/functions';
import { v4 as uuid } from 'uuid';
import { randomUUID as uuid, randomBytes } from 'crypto';
import { extractBindings } from './utils';

function createConsoleLogger(): Logger {
Expand Down Expand Up @@ -50,7 +50,7 @@ function createBaseContext(azFunction: AzureFunction, bindingDefinitions: Bindin
invocationId,
},
traceContext: {
traceparent: null,
traceparent: `00-${randomBytes(16).toString('hex')}-${randomBytes(8).toString('hex')}-00`,
tracestate: null,
attributes: null,
},
Expand Down
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"typescript": "^5.0.2"
},
"dependencies": {
"content-type": "^1.0.5",
"uuid": "^10.0.0"
"content-type": "^1.0.5"
}
}
9 changes: 3 additions & 6 deletions test/context-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('context-builder', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
() => {},
);
const { done, invocationId, log } = context;
const { done, invocationId, log, traceContext } = context;

expect(context).to.deep.equal({
invocationId,
Expand All @@ -47,12 +47,9 @@ describe('context-builder', () => {
retryContext: null,
},
log,
traceContext: {
attributes: null,
traceparent: null,
tracestate: null,
},
traceContext,
});
expect(traceContext.traceparent).to.match(/^00-[0-9a-f]{32}-[0-9a-f]{16}-00$/);
});
it('creates a context with multiple inputs', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
2 changes: 1 addition & 1 deletion test/function-runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const contextMatcher = match({
invocationId: match.string,
},
traceContext: {
traceparent: null,
traceparent: match.string,
tracestate: null,
attributes: null,
},
Expand Down
2 changes: 1 addition & 1 deletion test/queue-binding.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { match, stub } from 'sinon';
import { functionRunner, QueueBinding } from '../lib';
import { expect } from 'chai';
import { v4 as uuid } from 'uuid';
import { randomUUID as uuid } from 'crypto';

describe('queue-binding', () => {
it('executes a queue trigger', async () => {
Expand Down

0 comments on commit f63c897

Please sign in to comment.