@microsoft/agents-telemetry 1.5.0-beta.23.g2277c6f0ab

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 (90) hide show
  1. package/README.md +342 -0
  2. package/dist/cjs/package.json +73 -0
  3. package/dist/cjs/src/index.cjs +14 -0
  4. package/dist/cjs/src/index.cjs.map +1 -0
  5. package/dist/cjs/src/index.d.cts +93 -0
  6. package/dist/cjs/src/index.d.ts +13 -0
  7. package/dist/cjs/src/index.js +54 -0
  8. package/dist/cjs/src/index.js.map +1 -0
  9. package/dist/cjs/src/loggers/base.d.ts +21 -0
  10. package/dist/cjs/src/loggers/base.js +12 -0
  11. package/dist/cjs/src/loggers/base.js.map +1 -0
  12. package/dist/cjs/src/loggers/debug.d.ts +19 -0
  13. package/dist/cjs/src/loggers/debug.js +70 -0
  14. package/dist/cjs/src/loggers/debug.js.map +1 -0
  15. package/dist/cjs/src/loggers/otel.d.ts +10 -0
  16. package/dist/cjs/src/loggers/otel.js +77 -0
  17. package/dist/cjs/src/loggers/otel.js.map +1 -0
  18. package/dist/cjs/src/observability/category.d.ts +11 -0
  19. package/dist/cjs/src/observability/category.js +67 -0
  20. package/dist/cjs/src/observability/category.js.map +1 -0
  21. package/dist/cjs/src/observability/constants.d.ts +111 -0
  22. package/dist/cjs/src/observability/constants.js +136 -0
  23. package/dist/cjs/src/observability/constants.js.map +1 -0
  24. package/dist/cjs/src/observability/metric.d.ts +9 -0
  25. package/dist/cjs/src/observability/metric.js +18 -0
  26. package/dist/cjs/src/observability/metric.js.map +1 -0
  27. package/dist/cjs/src/observability/trace.d.ts +13 -0
  28. package/dist/cjs/src/observability/trace.js +135 -0
  29. package/dist/cjs/src/observability/trace.js.map +1 -0
  30. package/dist/cjs/src/types.d.ts +150 -0
  31. package/dist/cjs/src/types.js +7 -0
  32. package/dist/cjs/src/types.js.map +1 -0
  33. package/dist/cjs/src/utils/attempt.d.ts +30 -0
  34. package/dist/cjs/src/utils/attempt.js +53 -0
  35. package/dist/cjs/src/utils/attempt.js.map +1 -0
  36. package/dist/cjs/src/utils/noop.d.ts +18 -0
  37. package/dist/cjs/src/utils/noop.js +46 -0
  38. package/dist/cjs/src/utils/noop.js.map +1 -0
  39. package/dist/cjs/src/utils/platform.d.ts +8 -0
  40. package/dist/cjs/src/utils/platform.js +12 -0
  41. package/dist/cjs/src/utils/platform.js.map +1 -0
  42. package/dist/cjs/src/utils/setting.d.ts +11 -0
  43. package/dist/cjs/src/utils/setting.js +30 -0
  44. package/dist/cjs/src/utils/setting.js.map +1 -0
  45. package/dist/cjs/tsconfig.tsbuildinfo +1 -0
  46. package/dist/esm/package.json +3 -0
  47. package/dist/esm/src/index.d.mts +93 -0
  48. package/dist/esm/src/index.d.ts +13 -0
  49. package/dist/esm/src/index.js +51 -0
  50. package/dist/esm/src/index.js.map +1 -0
  51. package/dist/esm/src/index.mjs +15 -0
  52. package/dist/esm/src/index.mjs.map +1 -0
  53. package/dist/esm/src/loggers/base.d.ts +21 -0
  54. package/dist/esm/src/loggers/base.js +9 -0
  55. package/dist/esm/src/loggers/base.js.map +1 -0
  56. package/dist/esm/src/loggers/debug.d.ts +19 -0
  57. package/dist/esm/src/loggers/debug.js +63 -0
  58. package/dist/esm/src/loggers/debug.js.map +1 -0
  59. package/dist/esm/src/loggers/otel.d.ts +10 -0
  60. package/dist/esm/src/loggers/otel.js +74 -0
  61. package/dist/esm/src/loggers/otel.js.map +1 -0
  62. package/dist/esm/src/observability/category.d.ts +11 -0
  63. package/dist/esm/src/observability/category.js +64 -0
  64. package/dist/esm/src/observability/category.js.map +1 -0
  65. package/dist/esm/src/observability/constants.d.ts +111 -0
  66. package/dist/esm/src/observability/constants.js +133 -0
  67. package/dist/esm/src/observability/constants.js.map +1 -0
  68. package/dist/esm/src/observability/metric.d.ts +9 -0
  69. package/dist/esm/src/observability/metric.js +15 -0
  70. package/dist/esm/src/observability/metric.js.map +1 -0
  71. package/dist/esm/src/observability/trace.d.ts +13 -0
  72. package/dist/esm/src/observability/trace.js +132 -0
  73. package/dist/esm/src/observability/trace.js.map +1 -0
  74. package/dist/esm/src/types.d.ts +150 -0
  75. package/dist/esm/src/types.js +6 -0
  76. package/dist/esm/src/types.js.map +1 -0
  77. package/dist/esm/src/utils/attempt.d.ts +30 -0
  78. package/dist/esm/src/utils/attempt.js +49 -0
  79. package/dist/esm/src/utils/attempt.js.map +1 -0
  80. package/dist/esm/src/utils/noop.d.ts +18 -0
  81. package/dist/esm/src/utils/noop.js +41 -0
  82. package/dist/esm/src/utils/noop.js.map +1 -0
  83. package/dist/esm/src/utils/platform.d.ts +8 -0
  84. package/dist/esm/src/utils/platform.js +9 -0
  85. package/dist/esm/src/utils/platform.js.map +1 -0
  86. package/dist/esm/src/utils/setting.d.ts +11 -0
  87. package/dist/esm/src/utils/setting.js +27 -0
  88. package/dist/esm/src/utils/setting.js.map +1 -0
  89. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  90. package/package.json +73 -0
package/README.md ADDED
@@ -0,0 +1,342 @@
1
+ # @microsoft/agents-telemetry
2
+
3
+ ## Overview
4
+
5
+ The `@microsoft/agents-telemetry` package provides OpenTelemetry instrumentation primitives used across the Microsoft Agents SDK. It enables distributed tracing, structured log emission, and stable metric naming so you can monitor agent interactions, connector calls, storage operations, authentication flows, and turn processing.
6
+
7
+ The package exports:
8
+
9
+ - `trace` — span creation with record tracking, custom actions, and lifecycle hooks
10
+ - `debug` — loggers that bridge the `debug` module with OpenTelemetry log records
11
+ - `metric` — histogram and counter creation via the OpenTelemetry Meter API
12
+ - `SpanNames` / `MetricNames` — stable name constants for observability across the SDK
13
+
14
+ This package supports both ESM and CommonJS consumers and requires Node.js 20 or later.
15
+
16
+ ---
17
+
18
+ ## For Agent Developers
19
+
20
+ This section covers how to enable and configure telemetry in your agent application. The SDK automatically instruments its components — you only need to wire up OpenTelemetry exporters and, optionally, tune which span categories are active.
21
+
22
+ ### Peer Dependencies
23
+
24
+ Install the OpenTelemetry API packages in your agent for full integration:
25
+
26
+ ```sh
27
+ npm install @opentelemetry/api @opentelemetry/api-logs
28
+ ```
29
+
30
+ Both are optional. If missing, the SDK falls back to noop implementations and logs a warning. Installing the official packages is recommended for full tracing, metrics, and log export.
31
+
32
+ ### Enabling Tracing
33
+
34
+ For traces to be exported, configure the OpenTelemetry SDK with an exporter. Console exporter for development:
35
+
36
+ ```ts
37
+ import { NodeSDK } from '@opentelemetry/sdk-node'
38
+ import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-node'
39
+
40
+ const sdk = new NodeSDK({
41
+ traceExporter: new ConsoleSpanExporter(),
42
+ serviceName: 'my-agent-service',
43
+ })
44
+
45
+ sdk.start()
46
+ ```
47
+
48
+ Once configured, all SDK components that use `trace(...)` will emit spans through the global tracer provider.
49
+
50
+ To export metrics referenced by `MetricNames`, configure a metric reader/exporter in your OpenTelemetry SDK as well.
51
+
52
+ #### Production Setup with OTLP Exporter
53
+
54
+ For production, use an OTLP exporter to send traces to your observability backend (Azure Monitor, Jaeger, Grafana, etc.):
55
+
56
+ ```ts
57
+ import { NodeSDK } from '@opentelemetry/sdk-node'
58
+ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
59
+
60
+ const sdk = new NodeSDK({
61
+ traceExporter: new OTLPTraceExporter({
62
+ url: 'http://localhost:4318/v1/traces', // Your OTLP endpoint
63
+ }),
64
+ serviceName: 'my-agent-service',
65
+ })
66
+
67
+ sdk.start()
68
+ ```
69
+
70
+ ### Enabling Logs (OTLP)
71
+
72
+ To export logs produced by `debug` loggers to an OTLP backend, add a logs processor during startup:
73
+
74
+ ```ts
75
+ import { NodeSDK } from '@opentelemetry/sdk-node'
76
+ import { resourceFromAttributes } from '@opentelemetry/resources'
77
+ import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions'
78
+ import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-grpc'
79
+ import { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs'
80
+
81
+ const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4317'
82
+
83
+ const sdk = new NodeSDK({
84
+ resource: resourceFromAttributes({
85
+ [ATTR_SERVICE_NAME]: 'my-agent-service',
86
+ [ATTR_SERVICE_VERSION]: '1.0.0',
87
+ }),
88
+ logRecordProcessors: [
89
+ new BatchLogRecordProcessor(new OTLPLogExporter({ url: otlpEndpoint })),
90
+ ],
91
+ })
92
+
93
+ sdk.start()
94
+ ```
95
+
96
+ ### Disabling Span Categories
97
+
98
+ All built-in span categories are enabled by default. To disable one or more categories without changing code, set `AGENTS_TELEMETRY_DISABLED_SPAN_CATEGORIES` in your environment:
99
+
100
+ ```env
101
+ AGENTS_TELEMETRY_DISABLED_SPAN_CATEGORIES=STORAGE,AUTHORIZATION
102
+
103
+ # or
104
+
105
+ AGENTS_TELEMETRY_DISABLED_SPAN_CATEGORIES=STORAGE AUTHORIZATION
106
+ ```
107
+
108
+ Valid category names are:
109
+
110
+ - `STORAGE`
111
+ - `AUTHENTICATION`
112
+ - `AUTHORIZATION`
113
+ - `DIALOGS`
114
+
115
+ When a span category is disabled, instrumented code still runs normally with a noop context — no telemetry is emitted for those spans.
116
+
117
+ ### Span and Metric Names
118
+
119
+ The SDK uses predefined constants for all span and metric names:
120
+
121
+ ```ts
122
+ import { SpanNames, MetricNames } from '@microsoft/agents-telemetry'
123
+
124
+ // Example span names:
125
+ SpanNames.ADAPTER_PROCESS // 'agents.adapter.process'
126
+ SpanNames.AGENTS_APP_RUN // 'agents.app.run'
127
+ SpanNames.STORAGE_READ // 'agents.storage.read'
128
+ SpanNames.CONNECTOR_REPLY_TO_ACTIVITY // 'agents.connector.reply_to_activity'
129
+
130
+ // Example metric names:
131
+ MetricNames.ACTIVITIES_RECEIVED // 'agents.activities.received'
132
+ MetricNames.CONNECTOR_REQUEST_DURATION // 'agents.connector.request.duration'
133
+ MetricNames.TURN_DURATION // 'agents.turn.duration'
134
+ MetricNames.AUTH_TOKEN_REQUEST_COUNT // 'agents.auth.token.request.count'
135
+ // ... and more
136
+ ```
137
+
138
+ ---
139
+
140
+ ## For SDK Contributors
141
+
142
+ This section covers internal APIs used to instrument SDK components. If you are contributing to the Agents SDK packages, use `trace`, `debug`, and `metric` to add observability to your code.
143
+
144
+ Although this package is published, it primarily serves as a shared telemetry layer for other Agents SDK packages. Some exported TypeScript types intentionally depend on OpenTelemetry packages even though runtime behavior still supports noop fallback when those optional peer dependencies are not installed.
145
+
146
+ ### Using trace
147
+
148
+ Use `trace` to create validated spans. Every definition requires a `name` from `SpanNames`, a `record` object for tracking state, and an `end` hook called when the span finishes.
149
+
150
+ #### Callback mode
151
+
152
+ The span is started and ended automatically around the callback:
153
+
154
+ ```ts
155
+ import { SpanNames, trace } from '@microsoft/agents-telemetry'
156
+
157
+ const result = await trace(
158
+ {
159
+ name: SpanNames.AGENTS_APP_ROUTE_HANDLER,
160
+ record: { conversationId: '', messageCount: 0 },
161
+ actions: ({ span }) => ({
162
+ setAttribute: (key: string, value: string) => span.setAttribute(key, value),
163
+ }),
164
+ end: ({ span, record, duration, error }) => {
165
+ span.setAttribute('conversation.id', record.conversationId)
166
+ span.setAttribute('message.count', record.messageCount)
167
+ },
168
+ },
169
+ async ({ record, actions }) => {
170
+ record({ conversationId })
171
+ actions.setAttribute('code.function', 'handleMessage')
172
+ const result = await service.handleMessage(conversationId, text)
173
+ record({ messageCount: result.count })
174
+ return result
175
+ }
176
+ )
177
+ ```
178
+
179
+ #### Managed mode (no callback)
180
+
181
+ For long-lived operations where you need manual control over the span lifecycle:
182
+
183
+ ```ts
184
+ import { SpanNames, trace } from '@microsoft/agents-telemetry'
185
+
186
+ const { record, actions, end, fail } = trace({
187
+ name: SpanNames.ADAPTER_PROCESS,
188
+ record: { status: 'pending' },
189
+ end: ({ span, record, duration }) => {
190
+ span.setAttribute('status', record.status)
191
+ },
192
+ })
193
+
194
+ try {
195
+ record({ status: 'processing' })
196
+ await doWork()
197
+ record({ status: 'done' })
198
+ end()
199
+ } catch (error) {
200
+ fail(error)
201
+ end()
202
+ throw error
203
+ }
204
+ ```
205
+
206
+ #### Reusable definitions
207
+
208
+ Use `trace.define` to declare a trace definition with full type inference, without starting a span:
209
+
210
+ ```ts
211
+ const storageReadTrace = trace.define({
212
+ name: SpanNames.STORAGE_READ,
213
+ record: { keys: 0 },
214
+ end: ({ span, record }) => {
215
+ span.setAttribute('storage.keys', record.keys)
216
+ },
217
+ })
218
+
219
+ // Later:
220
+ trace(storageReadTrace, ({ record }) => {
221
+ record({ keys: 5 })
222
+ return storage.read(keys)
223
+ })
224
+ ```
225
+
226
+ #### Behavior details
227
+
228
+ - On success, the span status is set to `OK`.
229
+ - On failure, the exception is recorded on the span, status is set to `ERROR`, and the error is rethrown.
230
+ - Non-Error thrown values are recorded with their type name and string representation.
231
+ - Unrecognized span names throw immediately.
232
+ - Disabled span categories run the callback with a noop context — no telemetry is emitted.
233
+ - The `end` hook receives `{ span, record, duration, error? }`.
234
+
235
+ ### Using debug
236
+
237
+ Create loggers that emit to both the `debug` module and OpenTelemetry logs:
238
+
239
+ ```ts
240
+ import { debug } from '@microsoft/agents-telemetry'
241
+
242
+ const logger = debug('agents:mycomponent')
243
+ logger.info('Processing request', { requestId })
244
+ logger.error('Failed to connect', error)
245
+ ```
246
+
247
+ When `@opentelemetry/api-logs` is available, log records are emitted with severity and namespace attributes. Otherwise, only the `debug` output is produced.
248
+
249
+ ### Using metric
250
+
251
+ Create OpenTelemetry instruments for recording measurements:
252
+
253
+ ```ts
254
+ import { metric, MetricNames } from '@microsoft/agents-telemetry'
255
+
256
+ const duration = metric.histogram(MetricNames.TURN_DURATION)
257
+ const counter = metric.counter(MetricNames.ACTIVITIES_RECEIVED)
258
+
259
+ duration.record(elapsed, { 'activity.type': 'message' })
260
+ counter.add(1, { 'activity.type': 'message' })
261
+ ```
262
+
263
+ When `@opentelemetry/api` is not available, the instruments are safe noops.
264
+
265
+ ### Key Features
266
+
267
+ - **Automatic span lifecycle**: Spans are started and ended automatically in callback mode
268
+ - **Error recording**: Exceptions are recorded on the span with `ERROR` status
269
+ - **Span name validation**: Unknown span names are rejected early
270
+ - **Record tracking**: Accumulate structured data during a trace and access it in the `end` hook
271
+ - **Custom actions**: Define span-scoped helper functions via the `actions` factory
272
+ - **Category-based disabling**: Disable groups of spans via environment configuration
273
+ - **Noop fallback**: All instrumentation calls are safe no-ops when OpenTelemetry APIs are not installed
274
+
275
+ ---
276
+
277
+ ## API Reference
278
+
279
+ ### `trace(definition)` — Managed mode
280
+
281
+ Starts a span and returns a managed context with `record`, `actions`, `end`, and `fail` methods.
282
+
283
+ | Parameter | Type | Description |
284
+ |-----------|------|-------------|
285
+ | `definition` | `TraceDefinition` | Trace definition object (see below). |
286
+
287
+ Returns: `{ record, actions, end, fail }`
288
+
289
+ ### `trace(definition, callback)` — Callback mode
290
+
291
+ Runs `callback` inside an active span. The span is ended automatically when the callback returns or throws.
292
+
293
+ | Parameter | Type | Description |
294
+ |-----------|------|-------------|
295
+ | `definition` | `TraceDefinition` | Trace definition object (see below). |
296
+ | `callback` | `(context) => TReturn` | Callback receiving `{ record, actions }`. Return value (including a `Promise`) is forwarded. |
297
+
298
+ Returns: Whatever `callback` returns.
299
+
300
+ ### `TraceDefinition`
301
+
302
+ | Property | Type | Description |
303
+ |----------|------|-------------|
304
+ | `name` | `SpanName` | Span name. Must be one of `SpanNames` values. |
305
+ | `record` | `object` | Initial record state. Updated via `record()` during the trace. |
306
+ | `actions` | `(ctx: { span }) => object` | *(Optional)* Factory that receives the span and returns action helpers. |
307
+ | `end` | `(ctx: { span, record, duration, error? }) => void` | Hook called when the span ends. Use it to set final attributes or record metrics. |
308
+
309
+ ### `trace.define(definition)`
310
+
311
+ Returns the `definition` object as-is. Useful for declaring reusable trace definitions with full type inference.
312
+
313
+ ### `debug(namespace)`
314
+
315
+ Creates a logger for the given namespace. When `@opentelemetry/api-logs` is available, the logger bridges the `debug` module with OpenTelemetry log emission. Otherwise, it creates a `debug`-only logger.
316
+
317
+ | Parameter | Type | Description |
318
+ |-----------|------|-------------|
319
+ | `namespace` | `string` | Logger namespace (e.g. `'agents:hosting'`). |
320
+
321
+ Returns: `{ info, warn, error, debug }` — each method accepts a message string and optional arguments.
322
+
323
+ ### `metric`
324
+
325
+ Provides factory methods for creating OpenTelemetry instruments. When `@opentelemetry/api` is not available, returns noop instruments.
326
+
327
+ | Method | Description |
328
+ |--------|-------------|
329
+ | `metric.histogram(name)` | Creates a histogram instrument. |
330
+ | `metric.counter(name)` | Creates a counter instrument. |
331
+
332
+ ### `SpanNames`
333
+
334
+ Provides stable span name constants used by Agents SDK components, including adapter, application, connector, storage, authentication, authorization, user token client, turn-processing, and Copilot Studio client operations.
335
+
336
+ ### `MetricNames`
337
+
338
+ Provides stable metric name constants for counters and histograms used by Agents SDK components, including activity counts, request counts, turn counts, and duration metrics.
339
+
340
+ ## License
341
+
342
+ MIT
@@ -0,0 +1,73 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package.json",
3
+ "name": "@microsoft/agents-telemetry",
4
+ "version": "1.5.0-beta.23.g2277c6f0ab",
5
+ "homepage": "https://github.com/microsoft/Agents-for-js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/microsoft/Agents-for-js.git"
9
+ },
10
+ "author": {
11
+ "name": "Microsoft",
12
+ "email": "agentssdk@microsoft.com",
13
+ "url": "https://aka.ms/Agents"
14
+ },
15
+ "description": "Telemetry instrumentation for Microsoft Agents SDK",
16
+ "keywords": [
17
+ "Agents",
18
+ "Telemetry",
19
+ "OpenTelemetry",
20
+ "OTel"
21
+ ],
22
+ "main": "./dist/cjs/src/index.cjs",
23
+ "module": "./dist/esm/src/index.mjs",
24
+ "types": "./dist/esm/src/index.d.mts",
25
+ "browser": "./dist/esm/src/index.mjs",
26
+ "scripts": {
27
+ "clean:esm": "node -e \"require('node:fs').rmSync('dist/esm', { recursive: true, force: true })\"",
28
+ "build:esm": "tsc --project tsconfig.esm.json && node scripts/esm.mjs"
29
+ },
30
+ "peerDependencies": {
31
+ "@opentelemetry/api": "1",
32
+ "@opentelemetry/api-logs": ">=0.214.0 <1"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "@opentelemetry/api": {
36
+ "optional": true
37
+ },
38
+ "@opentelemetry/api-logs": {
39
+ "optional": true
40
+ }
41
+ },
42
+ "devDependencies": {
43
+ "@opentelemetry/api": "1",
44
+ "@opentelemetry/api-logs": "0.214.0"
45
+ },
46
+ "dependencies": {
47
+ "debug": "^4.4.3"
48
+ },
49
+ "license": "MIT",
50
+ "files": [
51
+ "README.md",
52
+ "dist",
53
+ "package.json"
54
+ ],
55
+ "exports": {
56
+ ".": {
57
+ "import": {
58
+ "types": "./dist/esm/src/index.d.mts",
59
+ "browser": "./dist/esm/src/index.mjs",
60
+ "default": "./dist/esm/src/index.mjs"
61
+ },
62
+ "require": {
63
+ "types": "./dist/cjs/src/index.d.cts",
64
+ "default": "./dist/cjs/src/index.cjs"
65
+ },
66
+ "default": "./dist/esm/src/index.mjs"
67
+ },
68
+ "./package.json": "./package.json"
69
+ },
70
+ "engines": {
71
+ "node": ">=20.0.0"
72
+ }
73
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ var _a;
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.metric = exports.trace = exports.debug = exports.MetricNames = exports.SpanNames = void 0;
9
+ const index_js_1 = require("./index.js");
10
+ _a = (0, index_js_1.index)({
11
+ otel: () => require('@opentelemetry/api'),
12
+ logs: () => require('@opentelemetry/api-logs'),
13
+ }), exports.SpanNames = _a.SpanNames, exports.MetricNames = _a.MetricNames, exports.debug = _a.debug, exports.trace = _a.trace, exports.metric = _a.metric;
14
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/index.cts"],"names":[],"mappings":";AAAA;;;GAGG;;;;AASH,yCAAkC;AAIrB,KAMT,IAAA,gBAAK,EAAC;IACR,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,oBAAoB,CAAS;IACjD,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,yBAAyB,CAAa;CAC3D,CAAC,EARA,iBAAS,iBACT,mBAAW,mBACX,aAAK,aACL,aAAK,aACL,cAAM,aAIN"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export type { TraceDefinition } from './types.js';
6
+ export declare const SpanNames: {
7
+ readonly ADAPTER_PROCESS: "agents.adapter.process";
8
+ readonly ADAPTER_SEND_ACTIVITIES: "agents.adapter.send_activities";
9
+ readonly ADAPTER_UPDATE_ACTIVITY: "agents.adapter.update_activity";
10
+ readonly ADAPTER_DELETE_ACTIVITY: "agents.adapter.delete_activity";
11
+ readonly ADAPTER_CONTINUE_CONVERSATION: "agents.adapter.continue_conversation";
12
+ readonly ADAPTER_CREATE_CONNECTOR_CLIENT: "agents.adapter.create_connector_client";
13
+ readonly ADAPTER_CREATE_USER_TOKEN_CLIENT: "agents.adapter.create_user_token_client";
14
+ readonly AGENTS_APP_RUN: "agents.app.run";
15
+ readonly AGENTS_APP_ROUTE_HANDLER: "agents.app.route_handler";
16
+ readonly AGENTS_APP_BEFORE_TURN: "agents.app.before_turn";
17
+ readonly AGENTS_APP_AFTER_TURN: "agents.app.after_turn";
18
+ readonly AGENTS_APP_DOWNLOAD_FILES: "agents.app.download_files";
19
+ readonly CONNECTOR_SEND_TO_CONVERSATION: "agents.connector.send_to_conversation";
20
+ readonly CONNECTOR_REPLY_TO_ACTIVITY: "agents.connector.reply_to_activity";
21
+ readonly CONNECTOR_UPDATE_ACTIVITY: "agents.connector.update_activity";
22
+ readonly CONNECTOR_DELETE_ACTIVITY: "agents.connector.delete_activity";
23
+ readonly CONNECTOR_CREATE_CONVERSATION: "agents.connector.create_conversation";
24
+ readonly CONNECTOR_GET_CONVERSATIONS: "agents.connector.get_conversations";
25
+ readonly CONNECTOR_GET_CONVERSATION_MEMBER: "agents.connector.get_conversation_member";
26
+ readonly CONNECTOR_UPLOAD_ATTACHMENT: "agents.connector.upload_attachment";
27
+ readonly CONNECTOR_GET_ATTACHMENT: "agents.connector.get_attachment";
28
+ readonly CONNECTOR_GET_ATTACHMENT_INFO: "agents.connector.get_attachment_info";
29
+ readonly STORAGE_READ: "agents.storage.read";
30
+ readonly STORAGE_WRITE: "agents.storage.write";
31
+ readonly STORAGE_DELETE: "agents.storage.delete";
32
+ readonly AGENT_CLIENT_POST_ACTIVITY: "agents.agent_client.post_activity";
33
+ readonly AUTHENTICATION_GET_ACCESS_TOKEN: "agents.authentication.get_access_token";
34
+ readonly AUTHENTICATION_ACQUIRE_TOKEN_ON_BEHALF_OF: "agents.authentication.acquire_token_on_behalf_of";
35
+ readonly AUTHENTICATION_GET_AGENTIC_INSTANCE_TOKEN: "agents.authentication.get_agentic_instance_token";
36
+ readonly AUTHENTICATION_GET_AGENTIC_USER_TOKEN: "agents.authentication.get_agentic_user_token";
37
+ readonly AUTHORIZATION_AGENTIC_TOKEN: "agents.authorization.agentic_token";
38
+ readonly AUTHORIZATION_AZURE_BOT_TOKEN: "agents.authorization.azure_bot_token";
39
+ readonly AUTHORIZATION_AZURE_BOT_SIGNIN: "agents.authorization.azure_bot_signin";
40
+ readonly AUTHORIZATION_AZURE_BOT_SIGNOUT: "agents.authorization.azure_bot_signout";
41
+ readonly USER_TOKEN_CLIENT_GET_USER_TOKEN: "agents.user_token_client.get_user_token";
42
+ readonly USER_TOKEN_CLIENT_SIGN_OUT: "agents.user_token_client.sign_out";
43
+ readonly USER_TOKEN_CLIENT_GET_SIGN_IN_RESOURCE: "agents.user_token_client.get_sign_in_resource";
44
+ readonly USER_TOKEN_CLIENT_EXCHANGE_TOKEN: "agents.user_token_client.exchange_token";
45
+ readonly USER_TOKEN_CLIENT_GET_TOKEN_OR_SIGN_IN_RESOURCE: "agents.user_token_client.get_token_or_sign_in_resource";
46
+ readonly USER_TOKEN_CLIENT_GET_TOKEN_STATUS: "agents.user_token_client.get_token_status";
47
+ readonly USER_TOKEN_CLIENT_GET_AAD_TOKENS: "agents.user_token_client.get_aad_tokens";
48
+ readonly PROACTIVE_STORE_CONVERSATION: "agents.proactive.store_conversation";
49
+ readonly PROACTIVE_GET_CONVERSATION: "agents.proactive.get_conversation";
50
+ readonly PROACTIVE_GET_CONVERSATION_OR_THROW: "agents.proactive.get_conversation_or_throw";
51
+ readonly PROACTIVE_DELETE_CONVERSATION: "agents.proactive.delete_conversation";
52
+ readonly PROACTIVE_SEND_ACTIVITY: "agents.proactive.send_activity";
53
+ readonly PROACTIVE_CONTINUE_CONVERSATION: "agents.proactive.continue_conversation";
54
+ readonly PROACTIVE_CREATE_CONVERSATION: "agents.proactive.create_conversation";
55
+ readonly TURN_SEND_ACTIVITIES: "agents.turn.send_activities";
56
+ readonly COPILOT_START_CONVERSATION: "agents.copilot_client.start_conversation";
57
+ readonly COPILOT_SEND_ACTIVITY: "agents.copilot_client.send_activity";
58
+ readonly COPILOT_POST_REQUEST: "agents.copilot_client.post_request";
59
+ readonly COPILOT_CREATE_CONNECTION: "agents.copilot_client.webchat.create_connection";
60
+ readonly COPILOT_EXECUTE_STREAMING: "agents.copilot_client.execute_streaming";
61
+ readonly COPILOT_SUBSCRIBE_ASYNC: "agents.copilot_client.subscribe_async";
62
+ }, MetricNames: {
63
+ readonly ADAPTER_PROCESS_DURATION: "agents.adapter.process.duration";
64
+ readonly ACTIVITIES_RECEIVED: "agents.activities.received";
65
+ readonly ACTIVITIES_SENT: "agents.activities.sent";
66
+ readonly ACTIVITIES_UPDATED: "agents.activities.updated";
67
+ readonly ACTIVITIES_DELETED: "agents.activities.deleted";
68
+ readonly CONNECTOR_REQUESTS: "agents.connector.request.count";
69
+ readonly CONNECTOR_REQUEST_DURATION: "agents.connector.request.duration";
70
+ readonly AGENT_CLIENT_REQUESTS: "agents.agent_client.request.count";
71
+ readonly AGENT_CLIENT_REQUEST_DURATION: "agents.agent_client.request.duration";
72
+ readonly TURNS_COUNT: "agents.turn.count";
73
+ readonly TURNS_ERRORS: "agents.turn.error.count";
74
+ readonly TURN_DURATION: "agents.turn.duration";
75
+ readonly STORAGE_OPERATION_DURATION: "agents.storage.operation.duration";
76
+ readonly AUTH_TOKEN_REQUEST_COUNT: "agents.auth.token.request.count";
77
+ readonly AUTH_TOKEN_DURATION: "agents.auth.token.duration";
78
+ readonly USER_TOKEN_CLIENT_REQUESTS: "agents.user_token_client.request.count";
79
+ readonly USER_TOKEN_CLIENT_REQUEST_DURATION: "agents.user_token_client.request.duration";
80
+ readonly PROACTIVE_OPERATION_COUNT: "agents.proactive.operation.count";
81
+ readonly PROACTIVE_OPERATION_DURATION: "agents.proactive.operation.duration";
82
+ readonly CSC_ACTIVITIES_RECEIVED: "agents.copilot_client.activities.received";
83
+ readonly CSC_ACTIVITIES_SENT: "agents.copilot_client.activities.sent";
84
+ readonly CSC_CONVERSATIONS_STARTED: "agents.copilot_client.conversations.started";
85
+ readonly CSC_WEBCHAT_CONNECTIONS: "agents.copilot_client.webchat.connection.count";
86
+ readonly CSC_REQUEST_COUNT: "agents.copilot_client.request.count";
87
+ readonly CSC_REQUEST_ERRORS: "agents.copilot_client.request.error.count";
88
+ readonly CSC_STREAM_DURATION: "agents.copilot_client.stream.duration";
89
+ readonly CSC_REQUEST_DURATION: "agents.copilot_client.request.duration";
90
+ readonly CSC_EXECUTE_STREAMING: "agents.copilot_client.execute_streaming.count";
91
+ readonly CSC_SUBSCRIBE_ASYNC: "agents.copilot_client.subscribe_async.count";
92
+ readonly CSC_SUBSCRIBE_EVENT: "agents.copilot_client.subscribe_event.count";
93
+ }, debug: (namespace: string) => import("./loggers/base.js").Logger, trace: import("./types.js").TraceFunction, metric: import("./types.js").Metric;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { Loader, LoaderReturn } from './types.js';
6
+ /**
7
+ * Loads the optional OpenTelemetry dependencies and returns the telemetry factory used by the package entrypoints.
8
+ *
9
+ * @remarks
10
+ * - The loader can be synchronous or asynchronous.
11
+ * - Missing optional dependencies only disable the related feature and emit a warning.
12
+ */
13
+ export declare function index<TLoader extends Loader>(loader: TLoader): LoaderReturn<TLoader>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.index = index;
8
+ const trace_js_1 = require("./observability/trace.js");
9
+ const metric_js_1 = require("./observability/metric.js");
10
+ const debug_js_1 = require("./loggers/debug.js");
11
+ const otel_js_1 = require("./loggers/otel.js");
12
+ const attempt_js_1 = require("./utils/attempt.js");
13
+ const constants_js_1 = require("./observability/constants.js");
14
+ const noop_js_1 = require("./utils/noop.js");
15
+ const logger = (0, debug_js_1.createDebugLogger)('agents:telemetry');
16
+ /**
17
+ * Loads the optional OpenTelemetry dependencies and returns the telemetry factory used by the package entrypoints.
18
+ *
19
+ * @remarks
20
+ * - The loader can be synchronous or asynchronous.
21
+ * - Missing optional dependencies only disable the related feature and emit a warning.
22
+ */
23
+ function index(loader) {
24
+ const otel = (0, attempt_js_1.attempt)({
25
+ try: () => loader.otel(),
26
+ catch: () => logger.warn('OpenTelemetry API not found. Install @opentelemetry/api as a dependency to enable tracing and metrics.')
27
+ });
28
+ const logs = (0, attempt_js_1.attempt)({
29
+ try: () => loader.logs(),
30
+ catch: () => logger.warn('OpenTelemetry API Logs not found. Install @opentelemetry/api-logs as a dependency to enable OTel logging.')
31
+ });
32
+ if ((0, attempt_js_1.isPromise)(otel) || (0, attempt_js_1.isPromise)(logs)) {
33
+ return Promise.all([otel, logs])
34
+ .then(([otel, logs]) => factory(otel, logs));
35
+ }
36
+ return factory(otel, logs);
37
+ }
38
+ /**
39
+ * Creates the runtime telemetry surface exposed by the package.
40
+ *
41
+ * @remarks
42
+ * - Logging combines debug output with OpenTelemetry logs when log support is available.
43
+ * - Trace and metric helpers fall back to no-op implementations when the OTel API is not installed.
44
+ */
45
+ function factory(otel, logs) {
46
+ return {
47
+ SpanNames: constants_js_1.SpanNames,
48
+ MetricNames: constants_js_1.MetricNames,
49
+ debug: logs ? ns => (0, debug_js_1.link)((0, debug_js_1.createDebugLogger)(ns), (0, otel_js_1.createOTelLogger)(logs, ns)) : debug_js_1.createDebugLogger,
50
+ trace: otel ? (0, trace_js_1.traceFactory)(otel) : noop_js_1.noopTrace,
51
+ metric: otel ? (0, metric_js_1.metricFactory)(otel) : (0, noop_js_1.noopMetric)(),
52
+ };
53
+ }
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAqBH,sBAiBC;AAnCD,uDAAuD;AACvD,yDAAyD;AACzD,iDAA4D;AAC5D,+CAAoD;AACpD,mDAAuD;AAEvD,+DAAqE;AACrE,6CAAuD;AAEvD,MAAM,MAAM,GAAG,IAAA,4BAAiB,EAAC,kBAAkB,CAAC,CAAA;AAEpD;;;;;;GAMG;AACH,SAAgB,KAAK,CAA0B,MAAe;IAC5D,MAAM,IAAI,GAAG,IAAA,oBAAO,EAAC;QACnB,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAU;QAChC,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,wGAAwG,CAAC;KACnI,CAAC,CAAA;IAEF,MAAM,IAAI,GAAG,IAAA,oBAAO,EAAC;QACnB,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAc;QACpC,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,2GAA2G,CAAC;KACtI,CAAC,CAAA;IAEF,IAAI,IAAA,sBAAS,EAAC,IAAI,CAAC,IAAI,IAAA,sBAAS,EAAC,IAAI,CAAC,EAAE,CAAC;QACvC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;aAC7B,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAA0B,CAAA;IACzE,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,EAAE,IAAI,CAA0B,CAAA;AACrD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,OAAO,CAAE,IAAW,EAAE,IAAe;IAC5C,OAAO;QACL,SAAS,EAAT,wBAAS;QACT,WAAW,EAAX,0BAAW;QACX,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAA,eAAI,EAAC,IAAA,4BAAiB,EAAC,EAAE,CAAC,EAAE,IAAA,0BAAgB,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,4BAAiB;QAC/F,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,IAAA,uBAAY,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,mBAAS;QAC5C,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,IAAA,yBAAa,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,oBAAU,GAAE;KAClD,CAAA;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Logger interface used by the Agents SDK telemetry surface.
7
+ */
8
+ export interface Logger {
9
+ info(message: string, ...args: any[]): void;
10
+ warn(message: string, ...args: any[]): void;
11
+ error(message: string, ...args: any[]): void;
12
+ debug(message: string, ...args: any[]): void;
13
+ }
14
+ /**
15
+ * Supported logger method names.
16
+ */
17
+ export type LoggerLevel = keyof Logger;
18
+ /**
19
+ * Ordered list of logger levels used when composing logger implementations.
20
+ */
21
+ export declare const levels: LoggerLevel[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.levels = void 0;
8
+ /**
9
+ * Ordered list of logger levels used when composing logger implementations.
10
+ */
11
+ exports.levels = ['info', 'warn', 'error', 'debug'];
12
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/loggers/base.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAiBH;;GAEG;AACU,QAAA,MAAM,GAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAU,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import createDebug from 'debug';
6
+ import type { LoggerLevel, Logger as BaseLogger } from './base.js';
7
+ type Logger = Record<LoggerLevel, createDebug.Debugger>;
8
+ /**
9
+ * Creates a debug logger with the specified namespace and log levels. The logger will use different colors for each log level and will work in both Node.js and browser environments.
10
+ */
11
+ export declare function createDebugLogger(namespace: string): Logger;
12
+ /**
13
+ * Links the debug logger with additional logger implementations.
14
+ *
15
+ * @remarks
16
+ * - Linked loggers only receive messages when the corresponding debug namespace is enabled.
17
+ */
18
+ export declare function link(debugLogger: Logger, ...loggers: BaseLogger[]): BaseLogger;
19
+ export {};