@@ -20,10 +20,15 @@ import {
2020} from "@trigger.dev/otlp-importer" ;
2121import type { MetricsV1Input } from "@internal/clickhouse" ;
2222import { logger } from "~/services/logger.server" ;
23- import { getClickhouseForOrganization } from "~/services/clickhouse/clickhouseFactory.server" ;
24- import { getEventRepositoryForOrganization } from "./eventRepository/eventRepositoryFactory.server" ;
23+ import { clickhouseClient } from "~/services/clickhouseInstance.server" ;
2524import { DynamicFlushScheduler } from "./dynamicFlushScheduler.server" ;
25+ import { ClickhouseEventRepository } from "./eventRepository/clickhouseEventRepository.server" ;
26+ import {
27+ clickhouseEventRepository ,
28+ clickhouseEventRepositoryV2 ,
29+ } from "./eventRepository/clickhouseEventRepositoryInstance.server" ;
2630import { generateSpanId } from "./eventRepository/common.server" ;
31+ import { EventRepository , eventRepository } from "./eventRepository/eventRepository.server" ;
2732import type {
2833 CreatableEventKind ,
2934 CreatableEventStatus ,
@@ -41,6 +46,9 @@ class OTLPExporter {
4146 private _tracer : Tracer ;
4247
4348 constructor (
49+ private readonly _eventRepository : EventRepository ,
50+ private readonly _clickhouseEventRepository : ClickhouseEventRepository ,
51+ private readonly _clickhouseEventRepositoryV2 : ClickhouseEventRepository ,
4452 private readonly _metricsFlushScheduler : DynamicFlushScheduler < MetricsV1Input > ,
4553 private readonly _verbose : boolean ,
4654 private readonly _spanAttributeValueLengthLimit : number
@@ -66,9 +74,7 @@ class OTLPExporter {
6674 } ) ;
6775 }
6876
69- async exportMetrics (
70- request : ExportMetricsServiceRequest
71- ) : Promise < ExportMetricsServiceResponse > {
77+ async exportMetrics ( request : ExportMetricsServiceRequest ) : Promise < ExportMetricsServiceResponse > {
7278 return await startSpan ( this . _tracer , "exportMetrics" , async ( span ) => {
7379 const rows = this . #filterResourceMetrics( request . resourceMetrics ) . flatMap (
7480 ( resourceMetrics ) => {
@@ -385,7 +391,10 @@ function convertSpansToCreateableEvents(
385391 SemanticInternalAttributes . METADATA
386392 ) ;
387393
388- const runTags = extractArrayAttribute ( span . attributes ?? [ ] , SemanticInternalAttributes . RUN_TAGS ) ;
394+ const runTags = extractArrayAttribute (
395+ span . attributes ?? [ ] ,
396+ SemanticInternalAttributes . RUN_TAGS
397+ ) ;
389398
390399 const properties =
391400 truncateAttributes (
@@ -456,7 +465,10 @@ function floorToTenSecondBucket(timeUnixNano: bigint | number): string {
456465 const flooredMs = Math . floor ( epochMs / 10_000 ) * 10_000 ;
457466 const date = new Date ( flooredMs ) ;
458467 // Format as ClickHouse DateTime: YYYY-MM-DD HH:MM:SS
459- return date . toISOString ( ) . replace ( "T" , " " ) . replace ( / \. \d { 3 } Z $ / , "" ) ;
468+ return date
469+ . toISOString ( )
470+ . replace ( "T" , " " )
471+ . replace ( / \. \d { 3 } Z $ / , "" ) ;
460472}
461473
462474function convertMetricsToClickhouseRows (
@@ -576,8 +588,7 @@ function resolveDataPointContext(
576588 attributes : Record < string , unknown > ;
577589} {
578590 const runId =
579- resourceCtx . runId ??
580- extractStringAttribute ( dpAttributes , SemanticInternalAttributes . RUN_ID ) ;
591+ resourceCtx . runId ?? extractStringAttribute ( dpAttributes , SemanticInternalAttributes . RUN_ID ) ;
581592 const taskSlug =
582593 resourceCtx . taskSlug ??
583594 extractStringAttribute ( dpAttributes , SemanticInternalAttributes . TASK_SLUG ) ;
0 commit comments