-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect version metadata binding, add attributes (#120)
* Detect version metadata binding, add attributes * Export isVersionMetadata * Rename attribute to script_version
- Loading branch information
Showing
6 changed files
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@microlabs/otel-cf-workers": patch | ||
--- | ||
|
||
Add version metadata to attributes if found |
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,19 @@ | ||
import { isVersionMetadata } from './env.js' | ||
|
||
export function versionAttributes(env: unknown): Record<string, string | undefined> { | ||
const attributes = {} as Record<string, string | undefined> | ||
|
||
if (typeof env === 'object' && env !== null) { | ||
for (const [binding, data] of Object.entries(env)) { | ||
if (isVersionMetadata(data)) { | ||
attributes['cf.script_version.binding'] = binding | ||
attributes['cf.script_version.id'] = data.id | ||
attributes['cf.script_version.tag'] = data.tag | ||
// Version metadata bindings are identical, so we can stop after the first one found | ||
break | ||
} | ||
} | ||
} | ||
|
||
return attributes | ||
} |