Export events to posthog too
This commit is contained in:
parent
63ede0b51a
commit
e7a7cf3eb8
1 changed files with 18 additions and 7 deletions
|
|
@ -14,8 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { SpanExporter } from "@opentelemetry/sdk-trace-base";
|
import { SpanExporter, ReadableSpan } from "@opentelemetry/sdk-trace-base";
|
||||||
import { ReadableSpan } from "@opentelemetry/sdk-trace-base";
|
|
||||||
import { ExportResult, ExportResultCode } from "@opentelemetry/core";
|
import { ExportResult, ExportResultCode } from "@opentelemetry/core";
|
||||||
|
|
||||||
import { PosthogAnalytics } from "./PosthogAnalytics";
|
import { PosthogAnalytics } from "./PosthogAnalytics";
|
||||||
|
|
@ -34,11 +33,23 @@ export class PosthogSpanExporter implements SpanExporter {
|
||||||
resultCallback: (result: ExportResult) => void
|
resultCallback: (result: ExportResult) => void
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
console.log("POSTHOGEXPORTER", spans);
|
console.log("POSTHOGEXPORTER", spans);
|
||||||
for (let i = 0; i < spans.length; i++) {
|
for (const span of spans) {
|
||||||
const span = spans[i];
|
const sendInstantly = [
|
||||||
const sendInstantly =
|
"otel_callEnded",
|
||||||
span.name == "otel_callEnded" ||
|
"otel_otherSentInstantlyEventName",
|
||||||
span.name == "otel_otherSentInstantlyEventName";
|
].includes(span.name);
|
||||||
|
|
||||||
|
for (const spanEvent of span.events) {
|
||||||
|
await PosthogAnalytics.instance.trackFromSpan(
|
||||||
|
{
|
||||||
|
eventName: spanEvent.name,
|
||||||
|
...spanEvent.attributes,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
send_instantly: sendInstantly,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await PosthogAnalytics.instance.trackFromSpan(
|
await PosthogAnalytics.instance.trackFromSpan(
|
||||||
{ eventName: span.name, ...span.attributes },
|
{ eventName: span.name, ...span.attributes },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue