Skip to content

Commit

Permalink
fix: Fallback to default trace endpoint for link exporter. (#444)
Browse files Browse the repository at this point in the history
<!--
Thank you for contributing to the project! 💜
Please see our [OSS process
document](https://github.com/honeycombio/home/blob/main/honeycomb-oss-lifecycle-and-practices.md#)
to get an idea of how we operate.
-->

## Which problem is this PR solving?

- Closes #443 

## Short description of the changes

Fall back to computed traces endpoint if not supplied.

## How to verify that this has the expected result
Configure the sample app (without) providing an end point and run:
```shell
npm run example:start:hello-world-web
```
You should see the SDK start successfully and links to traces in the
console.
  • Loading branch information
wolfgangcodes authored Jan 16, 2025
1 parent 4d72490 commit 496bd33
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const main = () => {
dataAttributes: ['hello', 'barBiz'],
},
},
localVisualizations: true,
});
sdk.start();
const tracer = trace.getTracer('click-tracer');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HoneycombOptions } from './types';
import {
createHoneycombSDKLogMessage,
getTracesApiKey,
getTracesEndpoint,
isClassic,
} from './util';
import {
Expand All @@ -24,7 +25,9 @@ export function configureConsoleTraceLinkExporter(
options?: HoneycombOptions,
): SpanExporter {
const apiKey = getTracesApiKey(options);
const { authRoot, uiRoot } = getUrlRoots(options?.endpoint);
const { authRoot, uiRoot } = getUrlRoots(
options?.tracesEndpoint || getTracesEndpoint(options),
);
return new ConsoleTraceLinkExporter(
options?.serviceName,
apiKey,
Expand Down
29 changes: 29 additions & 0 deletions packages/honeycomb-opentelemetry-web/test/honeycomb-debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,34 @@ describe('when debug is set to true', () => {
`@honeycombio/opentelemetry-web: Sample Rate configured for traces: '${testConfig.sampleRate}'`,
);
});
it('should log the configured options to the console when endpoint is omitted', () => {
const testConfig = {
debug: true,
apiKey: 'my-key',
serviceName: 'my-service',
sampleRate: 2,
};
new HoneycombWebSDK(testConfig);
expect(consoleSpy).toHaveBeenNthCalledWith(
3,
'@honeycombio/opentelemetry-web: 🐝 Honeycomb Web SDK Debug Mode Enabled 🐝',
);
expect(consoleSpy).toHaveBeenNthCalledWith(
4,
`@honeycombio/opentelemetry-web: API Key configured for traces: '${testConfig.apiKey}'`,
);
expect(consoleSpy).toHaveBeenNthCalledWith(
5,
`@honeycombio/opentelemetry-web: Service Name configured for traces: '${testConfig.serviceName}'`,
);
expect(consoleSpy).toHaveBeenNthCalledWith(
6,
`@honeycombio/opentelemetry-web: Endpoint configured for traces: 'https://api.honeycomb.io/v1/traces'`,
);
expect(consoleSpy).toHaveBeenNthCalledWith(
7,
`@honeycombio/opentelemetry-web: Sample Rate configured for traces: '${testConfig.sampleRate}'`,
);
});
});
});

0 comments on commit 496bd33

Please sign in to comment.