Skip to content

Commit b910b31

Browse files
committed
Expand instrumentation developer documentation.
1 parent 3026ea4 commit b910b31

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

src/instrumentation/README.md

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
Extend 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

89
export 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
3536
import { 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

Comments
 (0)