Skip to content

Commit

Permalink
Apply defaults configuration options in constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangcodes committed Jan 16, 2025
1 parent 4d72490 commit 1ac0c42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const main = () => {
// defaults to sending to US instance of Honeycomb
// endpoint: "https://api.eu1.honeycomb.io/v1/traces", // uncomment to send to EU instance
apiKey: 'api-key', // Replace with your Honeycomb Ingest API Key
serviceName: 'hny-web-distro-example:hello-world-web', // Replace with your application name. Honeycomb will name your dataset using this variable.
serviceName: 'hny-web-distro-example:JAN25:hello-world-web', // Replace with your application name. Honeycomb will name your dataset using this variable.
debug: true,
instrumentations: [
getWebAutoInstrumentations({
Expand All @@ -30,6 +30,7 @@ const main = () => {
dataAttributes: ['hello', 'barBiz'],
},
},
localVisualizations: true,
});
sdk.start();
const tracer = trace.getTracer('click-tracer');
Expand Down
20 changes: 11 additions & 9 deletions packages/honeycomb-opentelemetry-web/src/honeycomb-otel-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { configureDeterministicSampler } from './deterministic-sampler';
import { validateOptionsWarnings } from './validate-options';
import { WebVitalsInstrumentation } from './web-vitals-autoinstrumentation';
import { GlobalErrorsInstrumentation } from './global-errors-autoinstrumentation';
import { defaultOptions } from './util';

export class HoneycombWebSDK extends WebSDK {
constructor(options?: HoneycombOptions) {
Expand All @@ -28,9 +29,9 @@ export class HoneycombWebSDK extends WebSDK {
),
);
}

super({
...options,
const optionsWithDefaults = { ...defaultOptions, ...options };
const theOpts = {
...optionsWithDefaults,
instrumentations,
resource: mergeResources([
configureBrowserAttributesResource(),
Expand All @@ -39,17 +40,18 @@ export class HoneycombWebSDK extends WebSDK {
options?.resourceAttributes,
configureHoneycombResource(),
]),
sampler: configureDeterministicSampler(options),
sampler: configureDeterministicSampler(optionsWithDefaults),
// Exporter is configured through the span processor because
// the base SDK does not allow having both a spanProcessor and a
// traceExporter configured at the same time.
spanProcessor: configureSpanProcessors(options),
});
spanProcessor: configureSpanProcessors(optionsWithDefaults),
};
super(theOpts);

validateOptionsWarnings(options);
validateOptionsWarnings(optionsWithDefaults);

if (options?.debug) {
configureDebug(options);
if (optionsWithDefaults?.debug) {
configureDebug(optionsWithDefaults);
}
}
}

0 comments on commit 1ac0c42

Please sign in to comment.