Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-grapes-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/browser': minor
---

Added an optional otelResourceAttributes array to the BrowserSDKConfig type.
11 changes: 11 additions & 0 deletions packages/browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ HyperDX.init({
tracePropagationTargets: [/api.myapp.domain/i], // Set to link traces from frontend to backend requests
consoleCapture: true, // Capture console logs (default false)
advancedNetworkCapture: true, // Capture full HTTP request/response headers and bodies (default false)
otelResourceAttributes: [
{ key: 'service.version', value: '1.0.0' },
{ key: 'deployment.environment', value: 'production' },
],
});
```

Expand All @@ -38,6 +42,13 @@ HyperDX.init({
- `maskAllText` - (Optional) Whether to mask all text in session replay (default
`false`).
- `disableIntercom` - (Optional) Whether to disable Intercom integration (default `false`)
- `otelResourceAttributes` - (Optional) Array of key/value pairs to set as OpenTelemetry resource attributes and global attributes. Example:
```js
otelResourceAttributes: [
{ key: 'service.version', value: '1.0.0' },
{ key: 'deployment.environment', value: 'production' },
]
```
- `disableReplay` - (Optional) Whether to disable session replay (default `false`)
- `recordCanvas` - (Optional) Whether to record canvas elements (default `false`)
- `sampling` - (Optional) The sampling [config](https://github.com/rrweb-io/rrweb/blob/5fbb904edb653f3da17e6775ee438d81ef0bba83/docs/recipes/optimize-storage.md?plain=1#L22) in the session recording
Expand Down
8 changes: 8 additions & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type BrowserSDKConfig = {
service: string;
tracePropagationTargets?: (string | RegExp)[];
url?: string;
otelResourceAttributes?: Array<{ key: string; value: string }>;
};

const URL_BASE = 'https://in-otel.hyperdx.io';
Expand Down Expand Up @@ -64,6 +65,7 @@ class Browser {
service,
tracePropagationTargets,
url,
otelResourceAttributes,
}: BrowserSDKConfig) {
if (!hasWindow()) {
return;
Expand All @@ -81,6 +83,12 @@ class Browser {
);
}

if (otelResourceAttributes && otelResourceAttributes.length > 0) {
const attributesObj = Object.fromEntries(
otelResourceAttributes.map(({ key, value }) => [key, value])
);
this.setGlobalAttributes(attributesObj);
}
const urlBase = url ?? URL_BASE;

this._advancedNetworkCapture = advancedNetworkCapture;
Expand Down