@microsoft/agents-a365-observability-extensions-openai 0.1.0-preview.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +33 -0
  2. package/dist/cjs/Constants.d.ts +29 -0
  3. package/dist/cjs/Constants.d.ts.map +1 -0
  4. package/dist/cjs/Constants.js +37 -0
  5. package/dist/cjs/Constants.js.map +1 -0
  6. package/dist/cjs/OpenAIAgentsTraceInstrumentor.d.ts +43 -0
  7. package/dist/cjs/OpenAIAgentsTraceInstrumentor.d.ts.map +1 -0
  8. package/dist/cjs/OpenAIAgentsTraceInstrumentor.js +108 -0
  9. package/dist/cjs/OpenAIAgentsTraceInstrumentor.js.map +1 -0
  10. package/dist/cjs/OpenAIAgentsTraceProcessor.d.ts +84 -0
  11. package/dist/cjs/OpenAIAgentsTraceProcessor.d.ts.map +1 -0
  12. package/dist/cjs/OpenAIAgentsTraceProcessor.js +374 -0
  13. package/dist/cjs/OpenAIAgentsTraceProcessor.js.map +1 -0
  14. package/dist/cjs/Utils.d.ts +44 -0
  15. package/dist/cjs/Utils.d.ts.map +1 -0
  16. package/dist/cjs/Utils.js +221 -0
  17. package/dist/cjs/Utils.js.map +1 -0
  18. package/dist/cjs/index.d.ts +6 -0
  19. package/dist/cjs/index.d.ts.map +1 -0
  20. package/dist/cjs/index.js +14 -0
  21. package/dist/cjs/index.js.map +1 -0
  22. package/dist/esm/Constants.d.ts +29 -0
  23. package/dist/esm/Constants.d.ts.map +1 -0
  24. package/dist/esm/Constants.js +34 -0
  25. package/dist/esm/Constants.js.map +1 -0
  26. package/dist/esm/OpenAIAgentsTraceInstrumentor.d.ts +43 -0
  27. package/dist/esm/OpenAIAgentsTraceInstrumentor.d.ts.map +1 -0
  28. package/dist/esm/OpenAIAgentsTraceInstrumentor.js +104 -0
  29. package/dist/esm/OpenAIAgentsTraceInstrumentor.js.map +1 -0
  30. package/dist/esm/OpenAIAgentsTraceProcessor.d.ts +84 -0
  31. package/dist/esm/OpenAIAgentsTraceProcessor.d.ts.map +1 -0
  32. package/dist/esm/OpenAIAgentsTraceProcessor.js +337 -0
  33. package/dist/esm/OpenAIAgentsTraceProcessor.js.map +1 -0
  34. package/dist/esm/Utils.d.ts +44 -0
  35. package/dist/esm/Utils.d.ts.map +1 -0
  36. package/dist/esm/Utils.js +177 -0
  37. package/dist/esm/Utils.js.map +1 -0
  38. package/dist/esm/index.d.ts +6 -0
  39. package/dist/esm/index.d.ts.map +1 -0
  40. package/dist/esm/index.js +9 -0
  41. package/dist/esm/index.js.map +1 -0
  42. package/package.json +69 -0
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @microsoft/agents-a365-observability-extensions-openai
2
+
3
+ [![npm](https://img.shields.io/npm/v/@microsoft/agents-a365-observability-extensions-openai?label=npm&logo=npm)](https://www.npmjs.com/package/@microsoft/agents-a365-observability-extensions-openai)
4
+ [![npm Downloads](https://img.shields.io/npm/dm/@microsoft/agents-a365-observability-extensions-openai?label=Downloads&logo=npm)](https://www.npmjs.com/package/@microsoft/agents-a365-observability-extensions-openai)
5
+
6
+ OpenAI Agents SDK instrumentation for the Microsoft Agent 365 Observability SDK. This package provides automatic OpenTelemetry tracing and telemetry collection for OpenAI Agents SDK operations, including agent execution, function calls, and AI model interactions.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @microsoft/agents-a365-observability-extensions-openai
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ For detailed usage examples and implementation guidance, see the [Microsoft Agent 365 Observability Documentation](https://learn.microsoft.com/microsoft-agent-365/developer/observability?tabs=nodejs).
17
+
18
+ ## Support
19
+
20
+ For issues, questions, or feedback:
21
+
22
+ - File issues in the [GitHub Issues](https://github.com/microsoft/Agent365-nodejs/issues) section
23
+ - See the [main documentation](../../README.md) for more information
24
+
25
+ ## Trademarks
26
+
27
+ *Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653.*
28
+
29
+ ## License
30
+
31
+ Copyright (c) Microsoft Corporation. All rights reserved.
32
+
33
+ Licensed under the MIT License - see the [LICENSE](../../LICENSE.md) file for details
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Constants for OpenAI Agents SDK wrapper
3
+ */
4
+ export declare const GEN_AI_SPAN_KIND_AGENT_KEY = "agent";
5
+ export declare const GEN_AI_SPAN_KIND_TOOL_KEY = "tool";
6
+ export declare const GEN_AI_SPAN_KIND_CHAIN_KEY = "chain";
7
+ export declare const GEN_AI_SPAN_KIND_LLM_KEY = "chat";
8
+ export declare const GEN_AI_SPAN_KIND_RETRIEVER_KEY = "retriever";
9
+ export declare const GEN_AI_SPAN_KIND_EMBEDDING_KEY = "embedding";
10
+ export declare const GEN_AI_SPAN_KIND_RERANKER_KEY = "reranker";
11
+ export declare const GEN_AI_SPAN_KIND_GUARDRAIL_KEY = "guardrail";
12
+ export declare const GEN_AI_SPAN_KIND_EVALUATOR_KEY = "evaluator";
13
+ export declare const GEN_AI_SPAN_KIND_UNKNOWN_KEY = "unknown";
14
+ export declare const GEN_AI_MESSAGE_ROLE = "message_role";
15
+ export declare const GEN_AI_MESSAGE_CONTENT = "message_content";
16
+ export declare const GEN_AI_MESSAGE_CONTENTS = "message_contents";
17
+ export declare const GEN_AI_MESSAGE_CONTENT_TYPE = "content_type";
18
+ export declare const GEN_AI_MESSAGE_TOOL_CALLS = "message_tool_calls";
19
+ export declare const GEN_AI_MESSAGE_TOOL_CALL_ID = "message_tool_id";
20
+ export declare const GEN_AI_MESSAGE_TOOL_CALL_NAME = "message_tool_name";
21
+ export declare const GEN_AI_TOOL_JSON_SCHEMA = "tool_json_schema";
22
+ export declare const GEN_AI_LLM_TOKEN_COUNT_PROMPT_DETAILS_CACHED_READ = "llm_token_count_prompt_details_cached_read";
23
+ export declare const GEN_AI_LLM_TOKEN_COUNT_COMPLETION_DETAILS_REASONING = "llm_token_count_completion_details_reasoning";
24
+ export declare const GEN_AI_GRAPH_NODE_ID = "graph_node_id";
25
+ export declare const GEN_AI_GRAPH_NODE_PARENT_ID = "graph_node_parent_id";
26
+ export declare const GEN_AI_REQUEST_CONTENT_KEY = "gen_ai.request.content";
27
+ export declare const GEN_AI_RESPONSE_CONTENT_KEY = "gen_ai.response.content";
28
+ export declare const GEN_AI_EXECUTION_PAYLOAD_KEY = "gen_ai.execution.payload";
29
+ //# sourceMappingURL=Constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../src/Constants.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,eAAO,MAAM,0BAA0B,UAAU,CAAC;AAClD,eAAO,MAAM,yBAAyB,SAAS,CAAC;AAChD,eAAO,MAAM,0BAA0B,UAAU,CAAC;AAClD,eAAO,MAAM,wBAAwB,SAAS,CAAC;AAC/C,eAAO,MAAM,8BAA8B,cAAc,CAAC;AAC1D,eAAO,MAAM,8BAA8B,cAAc,CAAC;AAC1D,eAAO,MAAM,6BAA6B,aAAa,CAAC;AACxD,eAAO,MAAM,8BAA8B,cAAc,CAAC;AAC1D,eAAO,MAAM,8BAA8B,cAAc,CAAC;AAC1D,eAAO,MAAM,4BAA4B,YAAY,CAAC;AAGtD,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAClD,eAAO,MAAM,sBAAsB,oBAAoB,CAAC;AACxD,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAC1D,eAAO,MAAM,2BAA2B,iBAAiB,CAAC;AAC1D,eAAO,MAAM,yBAAyB,uBAAuB,CAAC;AAC9D,eAAO,MAAM,2BAA2B,oBAAoB,CAAC;AAC7D,eAAO,MAAM,6BAA6B,sBAAsB,CAAC;AACjE,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAC1D,eAAO,MAAM,iDAAiD,+CAA+C,CAAC;AAC9G,eAAO,MAAM,mDAAmD,iDAAiD,CAAC;AAClH,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AACpD,eAAO,MAAM,2BAA2B,yBAAyB,CAAC;AAElE,eAAO,MAAM,0BAA0B,2BAA2B,CAAC;AACnE,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AACrE,eAAO,MAAM,4BAA4B,6BAA6B,CAAC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ // ------------------------------------------------------------------------------
3
+ // Copyright (c) Microsoft Corporation. All rights reserved.
4
+ // ------------------------------------------------------------------------------
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GEN_AI_EXECUTION_PAYLOAD_KEY = exports.GEN_AI_RESPONSE_CONTENT_KEY = exports.GEN_AI_REQUEST_CONTENT_KEY = exports.GEN_AI_GRAPH_NODE_PARENT_ID = exports.GEN_AI_GRAPH_NODE_ID = exports.GEN_AI_LLM_TOKEN_COUNT_COMPLETION_DETAILS_REASONING = exports.GEN_AI_LLM_TOKEN_COUNT_PROMPT_DETAILS_CACHED_READ = exports.GEN_AI_TOOL_JSON_SCHEMA = exports.GEN_AI_MESSAGE_TOOL_CALL_NAME = exports.GEN_AI_MESSAGE_TOOL_CALL_ID = exports.GEN_AI_MESSAGE_TOOL_CALLS = exports.GEN_AI_MESSAGE_CONTENT_TYPE = exports.GEN_AI_MESSAGE_CONTENTS = exports.GEN_AI_MESSAGE_CONTENT = exports.GEN_AI_MESSAGE_ROLE = exports.GEN_AI_SPAN_KIND_UNKNOWN_KEY = exports.GEN_AI_SPAN_KIND_EVALUATOR_KEY = exports.GEN_AI_SPAN_KIND_GUARDRAIL_KEY = exports.GEN_AI_SPAN_KIND_RERANKER_KEY = exports.GEN_AI_SPAN_KIND_EMBEDDING_KEY = exports.GEN_AI_SPAN_KIND_RETRIEVER_KEY = exports.GEN_AI_SPAN_KIND_LLM_KEY = exports.GEN_AI_SPAN_KIND_CHAIN_KEY = exports.GEN_AI_SPAN_KIND_TOOL_KEY = exports.GEN_AI_SPAN_KIND_AGENT_KEY = void 0;
7
+ /**
8
+ * Constants for OpenAI Agents SDK wrapper
9
+ */
10
+ // Span Attribute Types
11
+ exports.GEN_AI_SPAN_KIND_AGENT_KEY = 'agent';
12
+ exports.GEN_AI_SPAN_KIND_TOOL_KEY = 'tool';
13
+ exports.GEN_AI_SPAN_KIND_CHAIN_KEY = 'chain';
14
+ exports.GEN_AI_SPAN_KIND_LLM_KEY = 'chat';
15
+ exports.GEN_AI_SPAN_KIND_RETRIEVER_KEY = 'retriever';
16
+ exports.GEN_AI_SPAN_KIND_EMBEDDING_KEY = 'embedding';
17
+ exports.GEN_AI_SPAN_KIND_RERANKER_KEY = 'reranker';
18
+ exports.GEN_AI_SPAN_KIND_GUARDRAIL_KEY = 'guardrail';
19
+ exports.GEN_AI_SPAN_KIND_EVALUATOR_KEY = 'evaluator';
20
+ exports.GEN_AI_SPAN_KIND_UNKNOWN_KEY = 'unknown';
21
+ // Message Prefixes
22
+ exports.GEN_AI_MESSAGE_ROLE = 'message_role';
23
+ exports.GEN_AI_MESSAGE_CONTENT = 'message_content';
24
+ exports.GEN_AI_MESSAGE_CONTENTS = 'message_contents';
25
+ exports.GEN_AI_MESSAGE_CONTENT_TYPE = 'content_type';
26
+ exports.GEN_AI_MESSAGE_TOOL_CALLS = 'message_tool_calls';
27
+ exports.GEN_AI_MESSAGE_TOOL_CALL_ID = 'message_tool_id';
28
+ exports.GEN_AI_MESSAGE_TOOL_CALL_NAME = 'message_tool_name';
29
+ exports.GEN_AI_TOOL_JSON_SCHEMA = 'tool_json_schema';
30
+ exports.GEN_AI_LLM_TOKEN_COUNT_PROMPT_DETAILS_CACHED_READ = 'llm_token_count_prompt_details_cached_read';
31
+ exports.GEN_AI_LLM_TOKEN_COUNT_COMPLETION_DETAILS_REASONING = 'llm_token_count_completion_details_reasoning';
32
+ exports.GEN_AI_GRAPH_NODE_ID = 'graph_node_id';
33
+ exports.GEN_AI_GRAPH_NODE_PARENT_ID = 'graph_node_parent_id';
34
+ exports.GEN_AI_REQUEST_CONTENT_KEY = 'gen_ai.request.content';
35
+ exports.GEN_AI_RESPONSE_CONTENT_KEY = 'gen_ai.response.content';
36
+ exports.GEN_AI_EXECUTION_PAYLOAD_KEY = 'gen_ai.execution.payload';
37
+ //# sourceMappingURL=Constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/Constants.ts"],"names":[],"mappings":";AAAA,iFAAiF;AACjF,4DAA4D;AAC5D,iFAAiF;;;AAEjF;;GAEG;AAEH,uBAAuB;AACV,QAAA,0BAA0B,GAAG,OAAO,CAAC;AACrC,QAAA,yBAAyB,GAAG,MAAM,CAAC;AACnC,QAAA,0BAA0B,GAAG,OAAO,CAAC;AACrC,QAAA,wBAAwB,GAAG,MAAM,CAAC;AAClC,QAAA,8BAA8B,GAAG,WAAW,CAAC;AAC7C,QAAA,8BAA8B,GAAG,WAAW,CAAC;AAC7C,QAAA,6BAA6B,GAAG,UAAU,CAAC;AAC3C,QAAA,8BAA8B,GAAG,WAAW,CAAC;AAC7C,QAAA,8BAA8B,GAAG,WAAW,CAAC;AAC7C,QAAA,4BAA4B,GAAG,SAAS,CAAC;AAEtD,mBAAmB;AACN,QAAA,mBAAmB,GAAG,cAAc,CAAC;AACrC,QAAA,sBAAsB,GAAG,iBAAiB,CAAC;AAC3C,QAAA,uBAAuB,GAAG,kBAAkB,CAAC;AAC7C,QAAA,2BAA2B,GAAG,cAAc,CAAC;AAC7C,QAAA,yBAAyB,GAAG,oBAAoB,CAAC;AACjD,QAAA,2BAA2B,GAAG,iBAAiB,CAAC;AAChD,QAAA,6BAA6B,GAAG,mBAAmB,CAAC;AACpD,QAAA,uBAAuB,GAAG,kBAAkB,CAAC;AAC7C,QAAA,iDAAiD,GAAG,4CAA4C,CAAC;AACjG,QAAA,mDAAmD,GAAG,8CAA8C,CAAC;AACrG,QAAA,oBAAoB,GAAG,eAAe,CAAC;AACvC,QAAA,2BAA2B,GAAG,sBAAsB,CAAC;AAErD,QAAA,0BAA0B,GAAG,wBAAwB,CAAC;AACtD,QAAA,2BAA2B,GAAG,yBAAyB,CAAC;AACxD,QAAA,4BAA4B,GAAG,0BAA0B,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { InstrumentationBase, InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
2
+ import { OpenAIAgentsTraceProcessor } from './OpenAIAgentsTraceProcessor';
3
+ /**
4
+ * Configuration options for the OpenAI Agents instrument
5
+ */
6
+ export interface OpenAIAgentsInstrumentationConfig extends InstrumentationConfig {
7
+ enabled?: boolean;
8
+ tracerName?: string;
9
+ tracerVersion?: string;
10
+ }
11
+ /**
12
+ * Instrumentor for OpenAI Agents SDK
13
+ * Automatically instruments the @openai/agents package to send traces to OpenTelemetry
14
+ */
15
+ export declare class OpenAIAgentsTraceInstrumentor extends InstrumentationBase<OpenAIAgentsInstrumentationConfig> {
16
+ private processor?;
17
+ private _hasBeenEnabled;
18
+ constructor(config?: OpenAIAgentsInstrumentationConfig);
19
+ /**
20
+ * Initialize the instrumentation modules
21
+ * This defines which npm packages to instrument
22
+ */
23
+ protected init(): InstrumentationModuleDefinition;
24
+ /**
25
+ * Returns the packages this instrumentation depends on
26
+ */
27
+ instrumentationDependencies(): readonly string[];
28
+ /**
29
+ * Enable instrumentation
30
+ * Sets up the trace processor and registers it with the OpenAI Agents SDK
31
+ */
32
+ enable(): void;
33
+ /**
34
+ * Disable instrumentation
35
+ * Cleans up the trace processor and unregisters it
36
+ */
37
+ disable(): void;
38
+ /**
39
+ * Get the trace processor instance
40
+ */
41
+ getProcessor(): OpenAIAgentsTraceProcessor | undefined;
42
+ }
43
+ //# sourceMappingURL=OpenAIAgentsTraceInstrumentor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAIAgentsTraceInstrumentor.d.ts","sourceRoot":"","sources":["../../src/OpenAIAgentsTraceInstrumentor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AAE7H,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAG1E;;GAEG;AACH,MAAM,WAAW,iCAAkC,SAAQ,qBAAqB;IAE9E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,6BAA8B,SAAQ,mBAAmB,CAAC,iCAAiC,CAAC;IACvG,OAAO,CAAC,SAAS,CAAC,CAA6B;IAC/C,OAAO,CAAC,eAAe,CAAS;gBAEpB,MAAM,GAAE,iCAAsC;IAmB1D;;;OAGG;IACH,SAAS,CAAC,IAAI,IAAI,+BAA+B;IAQjD;;OAEG;IACI,2BAA2B,IAAI,SAAS,MAAM,EAAE;IAIvD;;;OAGG;IACa,MAAM,IAAI,IAAI;IAkC9B;;;OAGG;IACa,OAAO,IAAI,IAAI;IAmB/B;;OAEG;IACI,YAAY,IAAI,0BAA0B,GAAG,SAAS;CAG9D"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ // ------------------------------------------------------------------------------
3
+ // Copyright (c) Microsoft Corporation. All rights reserved.
4
+ // ------------------------------------------------------------------------------
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OpenAIAgentsTraceInstrumentor = void 0;
7
+ /**
8
+ * Instrumentor for OpenAI Agents SDK
9
+ * Extends OpenTelemetry's InstrumentationBase to provide automatic tracing
10
+ */
11
+ const api_1 = require("@opentelemetry/api");
12
+ const instrumentation_1 = require("@opentelemetry/instrumentation");
13
+ const agents_a365_observability_1 = require("@microsoft/agents-a365-observability");
14
+ const OpenAIAgentsTraceProcessor_1 = require("./OpenAIAgentsTraceProcessor");
15
+ const agents_1 = require("@openai/agents");
16
+ /**
17
+ * Instrumentor for OpenAI Agents SDK
18
+ * Automatically instruments the @openai/agents package to send traces to OpenTelemetry
19
+ */
20
+ class OpenAIAgentsTraceInstrumentor extends instrumentation_1.InstrumentationBase {
21
+ constructor(config = {}) {
22
+ if (!agents_a365_observability_1.ObservabilityManager.getInstance()) {
23
+ throw new Error('ObservabilityManager is not configured yet. Please configure ObservabilityManager before initializing this instrumentor.');
24
+ }
25
+ const configWithDefaults = {
26
+ enabled: false,
27
+ ...config
28
+ };
29
+ super('agent365-openai-agents-instrumentor', '1.0.0', configWithDefaults);
30
+ this._hasBeenEnabled = false;
31
+ }
32
+ /**
33
+ * Initialize the instrumentation modules
34
+ * This defines which npm packages to instrument
35
+ */
36
+ init() {
37
+ return {
38
+ name: '@openai/agents',
39
+ supportedVersions: ['>=0.1.5'],
40
+ files: [],
41
+ };
42
+ }
43
+ /**
44
+ * Returns the packages this instrumentation depends on
45
+ */
46
+ instrumentationDependencies() {
47
+ return ['@openai/agents >= 0.1.5'];
48
+ }
49
+ /**
50
+ * Enable instrumentation
51
+ * Sets up the trace processor and registers it with the OpenAI Agents SDK
52
+ */
53
+ enable() {
54
+ // Prevent double-enabling
55
+ if (this._hasBeenEnabled) {
56
+ return;
57
+ }
58
+ this._hasBeenEnabled = true;
59
+ // Enable tracing in the OpenAI Agents SDK (it's disabled by default)
60
+ (0, agents_1.setTracingDisabled)(false);
61
+ // Get tracer name and version from config
62
+ const tracerName = this._config.tracerName;
63
+ const tracerVersion = this._config.tracerVersion;
64
+ // Get the configured tracer using OpenTelemetry API
65
+ const agent365Tracer = api_1.trace.getTracer(tracerName ?? 'agent365-openai-agents', tracerVersion);
66
+ // Get tracer provider
67
+ api_1.trace.getTracerProvider();
68
+ this.processor = new OpenAIAgentsTraceProcessor_1.OpenAIAgentsTraceProcessor(agent365Tracer);
69
+ // Register the processor directly using the imported setTraceProcessors function
70
+ // This bypasses the OpenTelemetry instrumentation patching mechanism
71
+ try {
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
+ (0, agents_1.setTraceProcessors)([this.processor]);
74
+ }
75
+ catch (error) {
76
+ // Silent failure - processor registration failed
77
+ }
78
+ super.enable();
79
+ }
80
+ /**
81
+ * Disable instrumentation
82
+ * Cleans up the trace processor and unregisters it
83
+ */
84
+ disable() {
85
+ if (this.processor) {
86
+ this.processor.shutdown();
87
+ this.processor = undefined;
88
+ }
89
+ // Reset flag to allow re-enabling
90
+ this._hasBeenEnabled = false;
91
+ // Reset trace processors using direct import
92
+ try {
93
+ (0, agents_1.setTraceProcessors)([]);
94
+ }
95
+ catch (error) {
96
+ // Silent failure - processor cleanup failed
97
+ }
98
+ super.disable();
99
+ }
100
+ /**
101
+ * Get the trace processor instance
102
+ */
103
+ getProcessor() {
104
+ return this.processor;
105
+ }
106
+ }
107
+ exports.OpenAIAgentsTraceInstrumentor = OpenAIAgentsTraceInstrumentor;
108
+ //# sourceMappingURL=OpenAIAgentsTraceInstrumentor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAIAgentsTraceInstrumentor.js","sourceRoot":"","sources":["../../src/OpenAIAgentsTraceInstrumentor.ts"],"names":[],"mappings":";AAAA,iFAAiF;AACjF,4DAA4D;AAC5D,iFAAiF;;;AAEjF;;;GAGG;AAEH,4CAA2C;AAC3C,oEAA6H;AAC7H,oFAA4E;AAC5E,6EAA0E;AAC1E,2CAA0F;AAY1F;;;GAGG;AACH,MAAa,6BAA8B,SAAQ,qCAAsD;IAIvG,YAAY,SAA4C,EAAE;QACxD,IAAI,CAAC,gDAAoB,CAAC,WAAW,EAAE,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACb,0HAA0H,CAC3H,CAAC;QACJ,CAAC;QAED,MAAM,kBAAkB,GAAG;YACzB,OAAO,EAAE,KAAK;YACd,GAAG,MAAM;SACV,CAAC;QAEF,KAAK,CACH,qCAAqC,EACrC,OAAO,EACP,kBAAkB,CACnB,CAAC;QAlBI,oBAAe,GAAG,KAAK,CAAC;IAmBhC,CAAC;IAED;;;OAGG;IACO,IAAI;QACZ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AAG,KAAK,CAAC;QAE7B,6CAA6C;QAC7C,IAAI,CAAC;YACH,IAAA,2BAAkB,EAAC,EAAE,CAAC,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,4CAA4C;QAC9C,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;IAED;;OAEG;IACI,YAAY;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF;AA7GD,sEA6GC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Trace processor for OpenAI Agents SDK
3
+ * Converts OpenAI Agents SDK spans to OpenTelemetry spans
4
+ */
5
+ import { Tracer as OtelTracer } from '@opentelemetry/api';
6
+ import { Span as AgentsSpan, SpanData } from '@openai/agents-core/dist/tracing/spans';
7
+ import { Trace as AgentTrace } from '@openai/agents-core/dist/tracing/traces';
8
+ import { TracingProcessor } from '@openai/agents-core/dist/tracing/processor';
9
+ /**
10
+ * Processor for OpenAI Agents SDK traces
11
+ */
12
+ export declare class OpenAIAgentsTraceProcessor implements TracingProcessor {
13
+ private static readonly MAX_HANDOFFS_IN_FLIGHT;
14
+ private readonly tracer;
15
+ private readonly rootSpans;
16
+ private readonly otelSpans;
17
+ private readonly tokens;
18
+ private readonly reverseHandoffsDict;
19
+ private readonly spanNames;
20
+ private readonly keyMappings;
21
+ constructor(tracer: OtelTracer);
22
+ private getNewKey;
23
+ /**
24
+ * Called to initialize the processor
25
+ */
26
+ start(): Promise<void>;
27
+ /**
28
+ * Called when a trace starts
29
+ */
30
+ onTraceStart(_trace: AgentTrace): Promise<void>;
31
+ /**
32
+ * Called when a trace ends
33
+ */
34
+ onTraceEnd(trace: AgentTrace): Promise<void>;
35
+ /**
36
+ * Called when a span starts
37
+ */
38
+ onSpanStart(span: AgentsSpan<SpanData>): Promise<void>;
39
+ /**
40
+ * Called when a span ends
41
+ */
42
+ onSpanEnd(span: AgentsSpan<SpanData>): Promise<void>;
43
+ /**
44
+ * Process span data based on type
45
+ */
46
+ private processSpanData;
47
+ /**
48
+ * Process response span data
49
+ */
50
+ private processResponseSpanData;
51
+ /**
52
+ * Process generation span data
53
+ */
54
+ private processGenerationSpanData;
55
+ /**
56
+ * Process function/tool span data
57
+ */
58
+ private processFunctionSpanData;
59
+ /**
60
+ * Process MCP list tools span data
61
+ */
62
+ private processMCPListToolsSpanData;
63
+ /**
64
+ * Process handoff span data
65
+ */
66
+ private processHandoffSpanData;
67
+ /**
68
+ * Process agent span data
69
+ */
70
+ private processAgentSpanData;
71
+ /**
72
+ * Stamp custom parent reference
73
+ */
74
+ private stampCustomParent;
75
+ /**
76
+ * Force flush
77
+ */
78
+ forceFlush(): Promise<void>;
79
+ /**
80
+ * Shutdown
81
+ */
82
+ shutdown(_timeout?: number): Promise<void>;
83
+ }
84
+ //# sourceMappingURL=OpenAIAgentsTraceProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAIAgentsTraceProcessor.d.ts","sourceRoot":"","sources":["../../src/OpenAIAgentsTraceProcessor.ts"],"names":[],"mappings":"AAIA;;;GAGG;AAEH,OAAO,EAAiD,MAAM,IAAI,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIzG,OAAO,EACL,IAAI,IAAI,UAAU,EAClB,QAAQ,EAET,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAO9E;;GAEG;AACH,qBAAa,0BAA2B,YAAW,gBAAgB;IACjE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,sBAAsB,CAAQ;IAEtD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoC;IAC9D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoC;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,O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