( /** * The prefix to add to all attribute keys. */ keyPrefix: string, /** * Function to transform attribute keys (e.g., camelCase to snake_case). */ transformKey: (key: string) => string )
| 320 | * @category Utilities |
| 321 | */ |
| 322 | export const addSpanAttributes = ( |
| 323 | /** |
| 324 | * The prefix to add to all attribute keys. |
| 325 | */ |
| 326 | keyPrefix: string, |
| 327 | /** |
| 328 | * Function to transform attribute keys (e.g., camelCase to snake_case). |
| 329 | */ |
| 330 | transformKey: (key: string) => string |
| 331 | ) => |
| 332 | <Attributes extends Record<string, any>>( |
| 333 | /** |
| 334 | * The OpenTelemetry span to add attributes to. |
| 335 | */ |
| 336 | span: Span, |
| 337 | /** |
| 338 | * The attributes to add to the span. |
| 339 | */ |
| 340 | attributes: Attributes |
| 341 | ): void => { |
| 342 | for (const [key, value] of Object.entries(attributes)) { |
| 343 | if (Predicate.isNotNullable(value)) { |
| 344 | span.attribute(`${keyPrefix}.${transformKey(key)}`, value) |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | const addSpanBaseAttributes = addSpanAttributes("gen_ai", String.camelToSnake)<BaseAttributes> |
| 350 | const addSpanOperationAttributes = addSpanAttributes("gen_ai.operation", String.camelToSnake)<OperationAttributes> |
no test coverage detected