-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure tracer initialization does not override DD_TAGS (#563)
* initial commit * fix lint * update tags code object instead
- Loading branch information
Showing
4 changed files
with
38 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { updateDDTags } from "./dd_tags"; | ||
|
||
describe("updateDDTags", () => { | ||
it("should work when updating an unset DD_TAGS", async () => { | ||
expect(process.env.DD_TAGS).toBeUndefined(); | ||
const tags = updateDDTags({ hello: "world" }); | ||
expect(tags).toEqual({ hello: "world" }); | ||
}); | ||
|
||
it("should work when updating a valid DD_TAGS", async () => { | ||
process.env.DD_TAGS = "datadog:bits"; | ||
const tags = updateDDTags({ hello: "world" }); | ||
expect(tags).toEqual({ datadog: "bits", hello: "world" }); | ||
}); | ||
|
||
it("should work when updating a valid DD_TAGS and comma at the end", async () => { | ||
process.env.DD_TAGS = "datadog:bits,"; | ||
const tags = updateDDTags({ hello: "world" }); | ||
expect(tags).toEqual({ datadog: "bits", hello: "world" }); | ||
}); | ||
}); |
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,12 @@ | ||
export function updateDDTags(newTags: Record<string, any> = {}): Record<string, any> { | ||
const envTags = (process.env.DD_TAGS ?? "") | ||
.split(",") | ||
.filter((pair) => pair.includes(":")) | ||
.reduce((acc: Record<string, any>, pair: string) => { | ||
const [key, value] = pair.split(":"); | ||
if (key && value) acc[key] = value; | ||
return acc; | ||
}, {}); | ||
|
||
return { ...envTags, ...newTags }; | ||
} |
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