Skip to content
Open
Show file tree
Hide file tree
Changes from all 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.
12 changes: 12 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: {
'service.version': '1.0.0',
'deployment.environment': 'production',
},
});
```

Expand All @@ -38,6 +42,14 @@ 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) Object containing OpenTelemetry resource attributes to be added to all spans. These are set at the resource level and merged with default SDK attributes. Example:
```js
otelResourceAttributes: {
'service.version': '1.0.0',
'deployment.environment': 'production',
'custom.attribute': 'value',
}
```
- `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
4 changes: 4 additions & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SessionRecorder, {
RumRecorderConfig,
} from '@hyperdx/otel-web-session-recorder';
import opentelemetry, { Attributes } from '@opentelemetry/api';
import { ResourceAttributes } from '@opentelemetry/resources';

import { resolveAsyncGlobal } from './utils';

Expand Down Expand Up @@ -32,6 +33,7 @@ type BrowserSDKConfig = {
service: string;
tracePropagationTargets?: (string | RegExp)[];
url?: string;
otelResourceAttributes?: ResourceAttributes;
};

const URL_BASE = 'https://in-otel.hyperdx.io';
Expand Down Expand Up @@ -64,6 +66,7 @@ class Browser {
service,
tracePropagationTargets,
url,
otelResourceAttributes,
}: BrowserSDKConfig) {
if (!hasWindow()) {
return;
Expand Down Expand Up @@ -92,6 +95,7 @@ class Browser {
apiKey,
applicationName: service,
ignoreUrls,
resourceAttributes: otelResourceAttributes,
instrumentations: {
visibility: true,
console: captureConsole ?? consoleCapture ?? false,
Expand Down
10 changes: 9 additions & 1 deletion packages/otel-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ export interface RumOtelWebConfig {
* Config options passed to web tracer
*/
tracer?: WebTracerConfig;

/**
* Additional resource attributes to be added to all spans.
* These will be merged with default SDK resource attributes.
*/
resourceAttributes?: ResourceAttributes;
}

interface RumOtelWebConfigInternal extends RumOtelWebConfig {
Expand Down Expand Up @@ -530,7 +536,7 @@ export const Rum: RumOtelWebType = {
processedOptions.cookieDomain,
).deinit;

const { ignoreUrls, applicationName, deploymentEnvironment, version } =
const { ignoreUrls, applicationName, deploymentEnvironment, version, resourceAttributes } =
processedOptions;
// enabled: false prevents registerInstrumentations from enabling instrumentations in constructor
// they will be enabled in registerInstrumentations
Expand All @@ -544,6 +550,8 @@ export const Rum: RumOtelWebType = {
// Splunk specific attributes
'rum.version': VERSION,
'rum.scriptInstance': instanceId,
// User-provided resource attributes
...(resourceAttributes || {}),
};

const syntheticsRunId = getSyntheticsRunId();
Expand Down
Loading