Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
aritro66 committed Apr 22, 2024
1 parent 87947cf commit f67e6e6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/session-recorder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const SplunkRumRecorder = {

const headers = {};
if (apiToken) {
headers['X-SF-Token'] = apiToken;
headers['authorization'] = apiToken;
}

if (rumAccessToken) {
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/exporters/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface SplunkExporterConfig {
onAttributesSerializing?: (attributes: Attributes, span: ReadableSpan) => Attributes,
xhrSender?: (url: string, data: string, headers?: Record<string, string>) => void,
beaconSender?: (url: string, data: string, headers?: Record<string, string>) => void,
apiToken?: string;
}

export function NOOP_ATTRIBUTES_TRANSFORMER(attributes: Attributes): Attributes {
Expand Down
5 changes: 4 additions & 1 deletion packages/web/src/exporters/otlp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ export class SplunkOTLPTraceExporter extends OTLPTraceExporter {
protected readonly _onAttributesSerializing: SplunkExporterConfig['onAttributesSerializing'];
protected readonly _xhrSender: SplunkExporterConfig['xhrSender'] = NATIVE_XHR_SENDER;
protected readonly _beaconSender: SplunkExporterConfig['beaconSender'] = typeof navigator !== 'undefined' && navigator.sendBeacon ? NATIVE_BEACON_SENDER : undefined;
private readonly apiToken: string;

constructor(options: SplunkExporterConfig) {
super(options);
this._onAttributesSerializing = options.onAttributesSerializing || NOOP_ATTRIBUTES_TRANSFORMER;
this.apiToken = options.apiToken as string;
}

convert(spans: ReadableSpan[]): IExportTraceServiceRequest {
Expand Down Expand Up @@ -61,7 +63,8 @@ export class SplunkOTLPTraceExporter extends OTLPTraceExporter {
// need to test with actual ingest
Accept: 'application/json',
'Content-Type': 'application/json',
...this.headers
authorization: this.apiToken,
...this.headers,
});
}

Expand Down
6 changes: 5 additions & 1 deletion packages/web/src/exporters/zipkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,35 @@ export class SplunkZipkinExporter implements SpanExporter {
private readonly _onAttributesSerializing: SplunkExporterConfig['onAttributesSerializing'];
private readonly _xhrSender: SplunkExporterConfig['xhrSender'];
private readonly _beaconSender: SplunkExporterConfig['beaconSender'];
private readonly apiToken: string;

constructor({
url,
onAttributesSerializing = NOOP_ATTRIBUTES_TRANSFORMER,
xhrSender = NATIVE_XHR_SENDER,
beaconSender = NATIVE_BEACON_SENDER,
apiToken,
}: SplunkExporterConfig) {
this.beaconUrl = url;
this._onAttributesSerializing = onAttributesSerializing;
this._xhrSender = xhrSender;
this._beaconSender = beaconSender;
this.apiToken = apiToken as string;
}

export(
spans: ReadableSpan[],
resultCallback: (result: ExportResult) => void
): void {
const zspans = spans.map(span => this._mapToZipkinSpan(span));
const zspans = spans.map((span) => this._mapToZipkinSpan(span));
const zJson = JSON.stringify(zspans);
if (document.hidden && this._beaconSender && zJson.length <= 64000) {
this._beaconSender(this.beaconUrl, zJson);
} else {
this._xhrSender!(this.beaconUrl, zJson, {
Accept: '*/*',
'Content-Type': 'text/plain;charset=UTF-8',
authorization: this.apiToken,
});
}
resultCallback({ code: ExportResultCode.SUCCESS });
Expand Down
5 changes: 4 additions & 1 deletion packages/web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export interface SplunkOtelWebConfig {
* Config options passed to web tracer
*/
tracer?: WebTracerConfig;

apiToken?: string;
}

interface SplunkOtelWebConfigInternal extends SplunkOtelWebConfig {
Expand Down Expand Up @@ -274,8 +276,9 @@ function buildExporter(options: SplunkOtelWebConfigInternal) {
const url = options.beaconEndpoint + (options.rumAccessToken ? '?auth='+options.rumAccessToken : '');
return options.exporter.factory({
url,
otlp: options.exporter.otlp,
otlp: true,
onAttributesSerializing: options.exporter.onAttributesSerializing,
apiToken: options.apiToken,
});
}

Expand Down

0 comments on commit f67e6e6

Please sign in to comment.