-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more propagation functions (#14)
* Add more propagation functions * Format files * Update readme * Readme again * Update version * Remove getTraceparentObject * Remove undefined function in index.ts * Update test equals check * Minor test refactor
- Loading branch information
1 parent
2884d9b
commit 8e9a1f2
Showing
7 changed files
with
69 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { getHttpTraceHeader } from "./lib/http"; | ||
export { getTraceparent, getTraceId } from "./lib/propagation"; | ||
export { decorateLogs, logger, Logger, LoggerOptions, DestinationStream } from "./lib/logging"; | ||
export { middleware } from "./lib/middleware"; | ||
export { createTraceparent } from "./lib/traceparent"; |
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
import { getStore } from "./middleware"; | ||
import { getTraceFromTraceparent } from "./traceparent"; | ||
|
||
/** | ||
* Retrieves traceparent string from the request context store that can be used | ||
* for requests to downstream services. | ||
* | ||
* Make sure you are using the `middleware` when using this. | ||
*/ | ||
export function getTraceparent(): string | undefined { | ||
return getStore()?.traceparent; | ||
} | ||
|
||
/** | ||
* Retrieves traceId from the request context store | ||
* | ||
* Make sure you are using the `middleware` when using this. | ||
*/ | ||
export function getTraceId(): string | undefined { | ||
const { traceparent } = getStore() || {}; | ||
return traceparent ? getTraceFromTraceparent(traceparent)?.traceId : undefined; | ||
} |
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 was deleted.
Oops, something went wrong.
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,39 @@ | ||
import type { RequestHandler } from "express"; | ||
|
||
import { getTraceparent, getTraceId } from "../../lib/propagation"; | ||
import { middleware as createMiddleware } from "../../lib/middleware"; | ||
|
||
describe("Propagations", () => { | ||
let middleware: RequestHandler; | ||
const traceparent = "00-abcdef0123456789abcdef0123456789-abcdef0123456789-01"; | ||
|
||
beforeEach(() => { | ||
middleware = createMiddleware(); | ||
}); | ||
|
||
describe("getTraceparent", () => { | ||
it("should get the traceparent string from the middleware context", async () => { | ||
// @ts-expect-error - We don't need the full Express Request object | ||
await middleware({ header: () => traceparent }, {}, () => { | ||
expect(getTraceparent()).to.equal(traceparent); | ||
}); | ||
}); | ||
|
||
it("should return undefined if run outside the middleware context", () => { | ||
expect(getTraceparent()).to.equal(undefined); | ||
}); | ||
}); | ||
|
||
describe("getTraceId", () => { | ||
it("should get the traceId from the middleware context", async () => { | ||
// @ts-expect-error - We don't need the full Express Request object | ||
await middleware({ header: () => traceparent }, {}, () => { | ||
expect(getTraceId()).to.equal("abcdef0123456789abcdef0123456789"); | ||
}); | ||
}); | ||
|
||
it("should return undefined if run outside the middleware context", () => { | ||
expect(getTraceId()).to.equal(undefined); | ||
}); | ||
}); | ||
}); |