otel for call start, end and mute

This is send over zipkin.
And it uses a posthog exporter to export events to posthog
using a _otel prefix
This commit is contained in:
Timo K
2023-03-10 10:33:54 +01:00
parent 0423a494c4
commit 4c59638d00
7 changed files with 490 additions and 12 deletions

View File

@@ -0,0 +1,57 @@
import { SpanExporter } from "@opentelemetry/sdk-trace-base";
import { ReadableSpan } from "@opentelemetry/sdk-trace-base";
import { ExportResult, ExportResultCode } from "@opentelemetry/core";
import { PosthogAnalytics } from "./PosthogAnalytics";
/**
* This is implementation of {@link SpanExporter} that prints spans to the
* console. This class can be used for diagnostic purposes.
*/
export class PosthogSpanExporter implements SpanExporter {
/**
* Export spans.
* @param spans
* @param resultCallback
*/
async export(
spans: ReadableSpan[],
resultCallback: (result: ExportResult) => void
): Promise<void> {
console.log("POSTHOGEXPORTER", spans);
for (let i = 0; i < spans.length; i++) {
const span = spans[i];
const sendInstantly =
span.name == "otel_callEnded" ||
span.name == "otel_otherSentInstantlyEventName";
await PosthogAnalytics.instance.trackFromSpan(
{ eventName: span.name, ...span.attributes },
{
send_instantly: sendInstantly,
}
);
resultCallback({ code: ExportResultCode.SUCCESS });
}
}
/**
* Shutdown the exporter.
*/
shutdown(): Promise<void> {
console.log("POSTHOGEXPORTER shutdown of otelPosthogExporter");
return new Promise<void>((resolve, _reject) => {
resolve();
});
}
/**
* converts span info into more readable format
* @param span
*/
// private _exportInfo;
/**
* Showing spans in console
* @param spans
* @param done
*/
// private _sendSpans;
}
//# sourceMappingURL=ConsoleSpanExporter.d.ts.map

View File

@@ -385,6 +385,22 @@ export class PosthogAnalytics {
this.capture(eventName, properties, options);
}
public async trackFromSpan(
{ eventName, ...properties },
options?: CaptureOptions
): Promise<void> {
if (this.identificationPromise) {
// only make calls to posthog after the identificaion is done
await this.identificationPromise;
}
if (
this.anonymity == Anonymity.Disabled ||
this.anonymity == Anonymity.Anonymous
)
return;
this.capture(eventName, properties, options);
}
public startListeningToSettingsChanges(): void {
// Listen to account data changes from sync so we can observe changes to relevant flags and update.
// This is called -