@@ -18,6 +18,27 @@ const LLMObsTagger = require('./tagger')
1818
1919const llmobsMetrics = telemetryMetrics . manager . namespace ( 'mlobs' )
2020
21+ function extractIntegrationFromTags ( tags ) {
22+ if ( ! Array . isArray ( tags ) ) return null
23+ const integrationTag = tags . find ( tag => tag . startsWith ( 'integration:' ) )
24+ if ( ! integrationTag ) return null
25+ return integrationTag . split ( ':' ) [ 1 ] || null
26+ }
27+
28+ function extractTagsFromSpanEvent ( event ) {
29+ const spanKind = event . meta ?. [ 'span.kind' ] || ''
30+ const integration = extractIntegrationFromTags ( event . tags )
31+ const error = event . status === 'error'
32+ const autoinstrumented = integration != null
33+
34+ return {
35+ span_kind : spanKind ,
36+ autoinstrumented : Number ( autoinstrumented ) ,
37+ error : error ? 1 : 0 ,
38+ integration : integration || 'N/A'
39+ }
40+ }
41+
2142function incrementLLMObsSpanStartCount ( tags , value = 1 ) {
2243 llmobsMetrics . count ( 'span.start' , tags ) . inc ( value )
2344}
@@ -53,7 +74,20 @@ function incrementLLMObsSpanFinishedCount (span, value = 1) {
5374 llmobsMetrics . count ( 'span.finished' , tags ) . inc ( value )
5475}
5576
77+ function recordLLMObsRawSpanSize ( event , rawEventSize ) {
78+ const tags = extractTagsFromSpanEvent ( event )
79+ llmobsMetrics . distribution ( 'span.raw_size' , tags ) . track ( rawEventSize )
80+ }
81+
82+ function recordLLMObsSpanSize ( event , eventSize , shouldTruncate ) {
83+ const tags = extractTagsFromSpanEvent ( event )
84+ tags . truncated = Number ( shouldTruncate )
85+ llmobsMetrics . distribution ( 'span.size' , tags ) . track ( eventSize )
86+ }
87+
5688module . exports = {
5789 incrementLLMObsSpanStartCount,
58- incrementLLMObsSpanFinishedCount
90+ incrementLLMObsSpanFinishedCount,
91+ recordLLMObsRawSpanSize,
92+ recordLLMObsSpanSize
5993}
0 commit comments