33Extend the ` InstrumentationBase ` class to create framework-specific instrumentors:
44
55``` typescript
6- import { InstrumentationBase } from ' agentops' ;
6+ import { InstrumentationBase } from ' ../base' ;
7+ import { InstrumentorMetadata } from ' ../../types' ;
78
89export class MyFrameworkInstrumentation extends InstrumentationBase {
9- static readonly metadata = {
10+ static readonly metadata: InstrumentorMetadata = {
1011 name: ' my-framework' ,
1112 version: ' 1.0.0' ,
1213 description: ' Instrumentation for My Framework' ,
@@ -29,22 +30,47 @@ export class MyFrameworkInstrumentation extends InstrumentationBase {
2930
3031## Registration
3132
32- Add your instrumentor to the registry in ` registry .ts` :
33+ Add your instrumentor to the registry in ` index .ts` :
3334
3435``` typescript
3536import { MyFrameworkInstrumentation } from ' ./my-framework' ;
3637
37- // Add to the instrumentations array
38- const instrumentations = [
38+ // Add to the AVAILABLE_INSTRUMENTORS array
39+ export const AVAILABLE_INSTRUMENTORS: (typeof InstrumentationBase )[] = [
40+ ...
3941 MyFrameworkInstrumentation ,
40- // ... other instrumentors
4142];
4243```
4344
44- ## Best Practices
45+ ## OpenTelemetry Semantic Conventions
4546
46- - Follow OpenTelemetry semantic conventions for attributes
47- - Use the provided attribute mapping utilities
48- - Implement proper cleanup in teardown methods
49- - Test with different versions of the target library
50- - Document any specific configuration requirements
47+ AgentOps follows [ OpenTelemetry GenAI semantic conventions] ( https://opentelemetry.io/docs/specs/semconv/gen-ai/ ) for consistent observability. Import semantic constants from the ` semconv ` modules:
48+
49+ ``` typescript
50+ import {
51+ GEN_AI_REQUEST_MODEL ,
52+ GEN_AI_USAGE_INPUT_TOKENS
53+ } from ' ../../semconv/model' ;
54+ ```
55+
56+ ## Attribute Mapping Utilities
57+
58+ Use the provided utilities to map framework data to OpenTelemetry attributes:
59+
60+ ``` typescript
61+ import {
62+ extractAttributesFromMapping ,
63+ AttributeMap
64+ } from ' ../../attributes' ;
65+
66+ // Define mapping from semantic conventions to your data structure
67+ const MODEL_ATTRIBUTES: AttributeMap = {
68+ [GEN_AI_REQUEST_MODEL ]: ' model_name' ,
69+ [GEN_AI_USAGE_INPUT_TOKENS ]: ' input_tokens' ,
70+ };
71+
72+ // Extract attributes from your framework's data
73+ const spanData = { model_name: ' gpt-4' , input_tokens: 150 };
74+ const attributes = extractAttributesFromMapping (spanData , MODEL_ATTRIBUTES );
75+ // Result: { 'gen_ai.request.model': 'gpt-4', 'gen_ai.usage.input_tokens': 150 }
76+ ```
0 commit comments