@@ -47,24 +47,37 @@ type LlmCriteria struct {
47
47
Criteria []sharedtypes.MaterialLlmCriterion
48
48
}
49
49
50
+ type DDTags string
51
+
52
+ const (
53
+ workflowTag DDTags = "dd.workflow"
54
+ LLMAssistedSelection DDTags = "LLMAssistedSelection"
55
+ apiKeyTag DDTags = "dd.api_keyVisible"
56
+ traceIDTag DDTags = "dd.trace_idVisible"
57
+ spanIDTag DDTags = "dd.span_idVisible"
58
+ parentIDTag DDTags = "dd.parent_idVisible"
59
+ )
60
+
50
61
// StartTrace generates a new trace ID and span ID for tracing
51
62
//
52
63
// Tags:
53
64
// - @displayName: Start new trace
54
65
//
55
66
// Parameters:
56
- // - str: a string
67
+ // - apiKey: the api key used for authentication
57
68
//
58
69
// Returns:
59
70
// - traceID: a 128-bit trace ID in decimal format
60
71
// - spanID: a 64-bit span ID in decimal format
61
- func StartTrace () (traceID string , spanID string ) {
72
+ func StartTrace (apiKey string ) (traceID string , spanID string ) {
62
73
traceID = generateTraceID ()
63
74
spanID = generateSpanID ()
64
75
ctx := & logging.ContextMap {}
65
- ctx .Set (logging .ContextKey ("dd.trace_idVisible" ), traceID )
66
- ctx .Set (logging .ContextKey ("dd.span_idVisible" ), spanID )
67
- logging .Log .Infof (ctx , "Starting new trace with trace ID: %s and span ID: %s" , traceID , spanID )
76
+ ctx .Set (logging .ContextKey (workflowTag ), LLMAssistedSelection )
77
+ ctx .Set (logging .ContextKey (apiKeyTag ), apiKey )
78
+ ctx .Set (logging .ContextKey (traceIDTag ), traceID )
79
+ ctx .Set (logging .ContextKey (spanIDTag ), spanID )
80
+ logging .Log .Infof (ctx , "Starting new trace for ApiKey: %s with trace ID: %s and span ID: %s" , apiKey , traceID , spanID )
68
81
69
82
return traceID , spanID
70
83
}
@@ -90,9 +103,10 @@ func CreateChildSpan(ctx *logging.ContextMap, traceID string, parentSpanID strin
90
103
childSpanID = generateSpanID ()
91
104
92
105
// Update the context with trace and span information
93
- ctx .Set (logging .ContextKey ("dd.trace_idVisible" ), traceID )
94
- ctx .Set (logging .ContextKey ("dd.span_idVisible" ), childSpanID )
95
- ctx .Set (logging .ContextKey ("dd.parent_idVisible" ), parentSpanID )
106
+ ctx .Set (logging .ContextKey (workflowTag ), LLMAssistedSelection )
107
+ ctx .Set (logging .ContextKey (traceIDTag ), traceID )
108
+ ctx .Set (logging .ContextKey (spanIDTag ), childSpanID )
109
+ ctx .Set (logging .ContextKey (parentIDTag ), parentSpanID )
96
110
97
111
logging .Log .Infof (ctx , "Starting child span with trace ID: %s, span ID: %s, and parent span ID: %s" , traceID , childSpanID , parentSpanID )
98
112
@@ -325,6 +339,7 @@ func PerformMultipleGeneralRequestsAndExtractAttributesWithOpenAiTokenOutput(inp
325
339
}
326
340
327
341
logging .Log .Debugf (ctx , "System prompt: %s" , systemPrompt )
342
+ logging .Log .Debugf (ctx , "User prompt: %s" , input )
328
343
329
344
// Collect all responses with child span for parallel execution
330
345
allResponses := runRequestsInParallel (n , sendRequest , traceID , childSpanID )
@@ -339,14 +354,16 @@ func PerformMultipleGeneralRequestsAndExtractAttributesWithOpenAiTokenOutput(inp
339
354
}
340
355
341
356
// get input token count
342
- inputTokenCount , _ := getTokenCount (tokenCountModelName , input , traceID , childSpanID )
343
- promptTokenCount , _ := getTokenCount (tokenCountModelName , systemPrompt , traceID , childSpanID )
357
+ userPromptTokenCount , _ := getTokenCount (tokenCountModelName , input , traceID , childSpanID )
358
+ systemPromptTokenCount , _ := getTokenCount (tokenCountModelName , systemPrompt , traceID , childSpanID )
359
+ inputTokenCount := (systemPromptTokenCount + userPromptTokenCount ) * n
344
360
345
361
// get the output token count
346
362
combinedResponseText := strings .Join (allResponses , "\n " )
347
363
outputTokenCount , _ := getTokenCount (tokenCountModelName , combinedResponseText , traceID , childSpanID )
348
364
349
- var totalTokenCount = (promptTokenCount + inputTokenCount )* n + outputTokenCount
365
+ var totalTokenCount = inputTokenCount + outputTokenCount
366
+ logging .Log .Debugf (ctx , "Input token count: %d" , inputTokenCount )
350
367
logging .Log .Debugf (ctx , "Output token count: %d" , outputTokenCount )
351
368
logging .Log .Debugf (ctx , "Total token count: %d" , totalTokenCount )
352
369
0 commit comments