autotel-bedrock 0.1.0
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.
- package/LICENSE +191 -0
- package/NOTICE +9 -0
- package/README.md +133 -0
- package/dist/index.cjs +208 -0
- package/dist/index.d.cts +113 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +202 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the
|
|
13
|
+
copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other
|
|
16
|
+
entities that control, are controlled by, or are under common control with
|
|
17
|
+
that entity. For the purposes of this definition, "control" means (i) the
|
|
18
|
+
power, direct or indirect, to cause the direction or management of such
|
|
19
|
+
entity, whether by contract or otherwise, or (ii) ownership of fifty
|
|
20
|
+
percent (50%) or more of the outstanding shares, or (iii) beneficial
|
|
21
|
+
ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
24
|
+
permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation source,
|
|
28
|
+
and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical transformation
|
|
31
|
+
or translation of a Source form, including but not limited to compiled
|
|
32
|
+
object code, generated documentation, and conversions to other media types.
|
|
33
|
+
|
|
34
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
35
|
+
made available under the License, as indicated by a copyright notice that
|
|
36
|
+
is included in or attached to the work (an example is provided in the
|
|
37
|
+
Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object form,
|
|
40
|
+
that is based on (or derived from) the Work and for which the editorial
|
|
41
|
+
revisions, annotations, elaborations, or other modifications represent, as
|
|
42
|
+
a whole, an original work of authorship. For the purposes of this License,
|
|
43
|
+
Derivative Works shall not include works that remain separable from, or
|
|
44
|
+
merely link (or bind by name) to the interfaces of, the Work and Derivative
|
|
45
|
+
Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
48
|
+
version of the Work and any modifications or additions to that Work or
|
|
49
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
50
|
+
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
51
|
+
Entity authorized to submit on behalf of the copyright owner. For the
|
|
52
|
+
purposes of this definition, "submitted" means any form of electronic,
|
|
53
|
+
verbal, or written communication sent to the Licensor or its
|
|
54
|
+
representatives, including but not limited to communication on electronic
|
|
55
|
+
mailing lists, source code control systems, and issue tracking systems that
|
|
56
|
+
are managed by, or on behalf of, the Licensor for the purpose of discussing
|
|
57
|
+
and improving the Work, but excluding communication that is conspicuously
|
|
58
|
+
marked or otherwise designated in writing by the copyright owner as "Not a
|
|
59
|
+
Contribution."
|
|
60
|
+
|
|
61
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on
|
|
62
|
+
behalf of whom a Contribution has been received by Licensor and
|
|
63
|
+
subsequently incorporated within the Work.
|
|
64
|
+
|
|
65
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
66
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
67
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
68
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
69
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
70
|
+
Object form.
|
|
71
|
+
|
|
72
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
73
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
74
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in
|
|
75
|
+
this section) patent license to make, have made, use, offer to sell, sell,
|
|
76
|
+
import, and otherwise transfer the Work, where such license applies only to
|
|
77
|
+
those patent claims licensable by such Contributor that are necessarily
|
|
78
|
+
infringed by their Contribution(s) alone or by combination of their
|
|
79
|
+
Contribution(s) with the Work to which such Contribution(s) was submitted.
|
|
80
|
+
If You institute patent litigation against any entity (including a
|
|
81
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
|
82
|
+
Contribution incorporated within the Work constitutes direct or
|
|
83
|
+
contributory patent infringement, then any patent licenses granted to You
|
|
84
|
+
under this License for that Work shall terminate as of the date such
|
|
85
|
+
litigation is filed.
|
|
86
|
+
|
|
87
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
88
|
+
Derivative Works thereof in any medium, with or without modifications, and
|
|
89
|
+
in Source or Object form, provided that You meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
92
|
+
a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works that
|
|
98
|
+
You distribute, all copyright, patent, trademark, and attribution notices
|
|
99
|
+
from the Source form of the Work, excluding those notices that do not
|
|
100
|
+
pertain to any part of the Derivative Works; and
|
|
101
|
+
|
|
102
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
103
|
+
distribution, then any Derivative Works that You distribute must include a
|
|
104
|
+
readable copy of the attribution notices contained within such NOTICE file,
|
|
105
|
+
excluding those notices that do not pertain to any part of the Derivative
|
|
106
|
+
Works, in at least one of the following places: within a NOTICE text file
|
|
107
|
+
distributed as part of the Derivative Works; within the Source form or
|
|
108
|
+
documentation, if provided along with the Derivative Works; or, within a
|
|
109
|
+
display generated by the Derivative Works, if and wherever such third-party
|
|
110
|
+
notices normally appear. The contents of the NOTICE file are for
|
|
111
|
+
informational purposes only and do not modify the License. You may add Your
|
|
112
|
+
own attribution notices within Derivative Works that You distribute,
|
|
113
|
+
alongside or as an addendum to the NOTICE text from the Work, provided that
|
|
114
|
+
such additional attribution notices cannot be construed as modifying the
|
|
115
|
+
License.
|
|
116
|
+
|
|
117
|
+
You may add Your own copyright statement to Your modifications and may
|
|
118
|
+
provide additional or different license terms and conditions for use,
|
|
119
|
+
reproduction, or distribution of Your modifications, or for any such
|
|
120
|
+
Derivative Works as a whole, provided Your use, reproduction, and
|
|
121
|
+
distribution of the Work otherwise complies with the conditions stated in
|
|
122
|
+
this License.
|
|
123
|
+
|
|
124
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
125
|
+
Contribution intentionally submitted for inclusion in the Work by You to
|
|
126
|
+
the Licensor shall be under the terms and conditions of this License,
|
|
127
|
+
without any additional terms or conditions. Notwithstanding the above,
|
|
128
|
+
nothing herein shall supersede or modify the terms of any separate license
|
|
129
|
+
agreement you may have executed with Licensor regarding such Contributions.
|
|
130
|
+
|
|
131
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
132
|
+
names, trademarks, service marks, or product names of the Licensor, except
|
|
133
|
+
as required for reasonable and customary use in describing the origin of
|
|
134
|
+
the Work and reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to
|
|
137
|
+
in writing, Licensor provides the Work (and each Contributor provides its
|
|
138
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
139
|
+
KIND, either express or implied, including, without limitation, any
|
|
140
|
+
warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or
|
|
141
|
+
FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for
|
|
142
|
+
determining the appropriateness of using or redistributing the Work and
|
|
143
|
+
assume any risks associated with Your exercise of permissions under this
|
|
144
|
+
License.
|
|
145
|
+
|
|
146
|
+
8. Limitation of Liability. In no event and under no legal theory, whether
|
|
147
|
+
in tort (including negligence), contract, or otherwise, unless required by
|
|
148
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to
|
|
149
|
+
in writing, shall any Contributor be liable to You for damages, including
|
|
150
|
+
any direct, indirect, special, incidental, or consequential damages of any
|
|
151
|
+
character arising as a result of this License or out of the use or
|
|
152
|
+
inability to use the Work (including but not limited to damages for loss of
|
|
153
|
+
goodwill, work stoppage, computer failure or malfunction, or any and all
|
|
154
|
+
other commercial damages or losses), even if such Contributor has been
|
|
155
|
+
advised of the possibility of such damages.
|
|
156
|
+
|
|
157
|
+
9. Accepting Warranty or Additional Liability. While redistributing the
|
|
158
|
+
Work or Derivative Works thereof, You may choose to offer, and charge a fee
|
|
159
|
+
for, acceptance of support, warranty, indemnity, or other liability
|
|
160
|
+
obligations and/or rights consistent with this License. However, in
|
|
161
|
+
accepting such obligations, You may act only on Your own behalf and on Your
|
|
162
|
+
sole responsibility, not on behalf of any other Contributor, and only if
|
|
163
|
+
You agree to indemnify, defend, and hold each Contributor harmless for any
|
|
164
|
+
liability incurred by, or claims asserted against, such Contributor by
|
|
165
|
+
reason of your accepting any such warranty or additional liability.
|
|
166
|
+
|
|
167
|
+
END OF TERMS AND CONDITIONS
|
|
168
|
+
|
|
169
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
170
|
+
|
|
171
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
172
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
|
173
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
174
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
175
|
+
recommend that a file or class name and description of purpose be included
|
|
176
|
+
on the same "printed page" as the copyright notice for easier
|
|
177
|
+
identification within third-party archives.
|
|
178
|
+
|
|
179
|
+
Copyright [yyyy] [name of copyright owner]
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
autotel
|
|
2
|
+
Copyright 2026 Jag Reehal
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0.
|
|
5
|
+
See the LICENSE file for the full license text.
|
|
6
|
+
|
|
7
|
+
"autotel" is a trademark of Jag Reehal. The Apache License, Version 2.0
|
|
8
|
+
does not grant rights to use the "autotel" name. See TRADEMARKS.md for
|
|
9
|
+
the trademark policy.
|
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# autotel-bedrock
|
|
2
|
+
|
|
3
|
+
**Bedrock is a provider, not a destination.**
|
|
4
|
+
|
|
5
|
+
`autotel-genai` already emits canonical `gen_ai.*` spans for every AI SDK call
|
|
6
|
+
against Amazon Bedrock — `gen_ai.provider.name = aws.bedrock`, the model id,
|
|
7
|
+
token usage, input and output messages — from nothing but the observer:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { registerTelemetry } from 'ai';
|
|
11
|
+
import { autotelTelemetry } from 'autotel-genai/observer';
|
|
12
|
+
|
|
13
|
+
registerTelemetry(autotelTelemetry());
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**This package is not required for any of it.** It fills in the Bedrock facts
|
|
17
|
+
no OpenTelemetry convention covers and no generic price table knows.
|
|
18
|
+
|
|
19
|
+
## What this package adds
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { init } from 'autotel';
|
|
23
|
+
import { registerTelemetry } from 'ai';
|
|
24
|
+
import { autotelTelemetry } from 'autotel-genai/observer';
|
|
25
|
+
import {
|
|
26
|
+
bedrockCompatibility,
|
|
27
|
+
bedrockProviderAttributes,
|
|
28
|
+
BEDROCK_PRICING,
|
|
29
|
+
} from 'autotel-bedrock';
|
|
30
|
+
|
|
31
|
+
init({
|
|
32
|
+
service: 'payments-bot',
|
|
33
|
+
spanEnrichers: [bedrockCompatibility({ region: 'eu-west-1' })],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
registerTelemetry(
|
|
37
|
+
autotelTelemetry({
|
|
38
|
+
pricing: BEDROCK_PRICING,
|
|
39
|
+
providerAttributes: bedrockProviderAttributes,
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### One model, three spellings
|
|
45
|
+
|
|
46
|
+
Bedrock accepts the same model as a foundation-model id, a cross-region
|
|
47
|
+
inference profile, or an inference-profile ARN:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
anthropic.claude-sonnet-4-5-20250929-v1:0
|
|
51
|
+
eu.anthropic.claude-sonnet-4-5-20250929-v1:0
|
|
52
|
+
arn:aws:bedrock:eu-west-1:123456789012:inference-profile/eu.anthropic.claude-sonnet-4-5-20250929-v1:0
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Dashboards group by `gen_ai.request.model` and Datadog / Langfuse price by it,
|
|
56
|
+
so a profile or ARN splits one model into several rows and drops the cost
|
|
57
|
+
(`cost_estimate_status:skipped_unsupported_model_pricing`). The enricher
|
|
58
|
+
rewrites `gen_ai.request.model` / `gen_ai.response.model` to the foundation id
|
|
59
|
+
and keeps the rest as their own attributes:
|
|
60
|
+
|
|
61
|
+
| Attribute | Value |
|
|
62
|
+
| -------------------------------------- | ------------------------------------------- |
|
|
63
|
+
| `gen_ai.request.model` | `anthropic.claude-sonnet-4-5-20250929-v1:0` |
|
|
64
|
+
| `aws.bedrock.model.id_raw` | what the request actually said |
|
|
65
|
+
| `aws.bedrock.model.arn` | the ARN, when one was used |
|
|
66
|
+
| `aws.bedrock.inference_profile.region` | `eu`, `us`, `global`… |
|
|
67
|
+
| `aws.bedrock.model.vendor` | `anthropic`, `amazon`, `meta`, `zai`… |
|
|
68
|
+
| `cloud.provider` / `cloud.region` | `aws` / the option or `AWS_REGION` |
|
|
69
|
+
|
|
70
|
+
Pass `normalizeModel: false` to keep the requested spelling and only add the
|
|
71
|
+
extra attributes. Spans from every other provider pass through untouched.
|
|
72
|
+
|
|
73
|
+
Use `spanEnrichers`, not `spanProcessors`. The latter replaces the pipeline
|
|
74
|
+
autotel builds, which would switch off the destinations you just configured.
|
|
75
|
+
|
|
76
|
+
### Stop reason and guardrails
|
|
77
|
+
|
|
78
|
+
The AI SDK folds Bedrock's stop reasons into its own (`guardrail_intervened`
|
|
79
|
+
and `content_filtered` both become `content-filter`; `malformed_tool_use` and
|
|
80
|
+
`model_context_window_exceeded` become `other`), and the lifecycle events
|
|
81
|
+
never see the guardrail trace. `bedrockProviderAttributes` puts both back:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
registerTelemetry(
|
|
85
|
+
autotelTelemetry({
|
|
86
|
+
pricing: BEDROCK_PRICING,
|
|
87
|
+
providerAttributes: bedrockProviderAttributes,
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
| Attribute | Value |
|
|
93
|
+
| ---------------------------------- | --------------------------------------------------------- |
|
|
94
|
+
| `aws.bedrock.stop_reason` | `end_turn`, `max_tokens`, `guardrail_intervened`… |
|
|
95
|
+
| `aws.bedrock.guardrail.intervened` | `true` when the guardrail stopped generation |
|
|
96
|
+
| `aws.bedrock.guardrail.id` | from the trace, so set `guardrailConfig.trace: 'enabled'` |
|
|
97
|
+
|
|
98
|
+
`gen_ai.response.finish_reasons` keeps the AI SDK's unified value, so a
|
|
99
|
+
dashboard built on it still works. An intervention is a policy outcome, not a
|
|
100
|
+
failure: the span's status stays unset, and `guardrail.intervened / total` is
|
|
101
|
+
one query away.
|
|
102
|
+
|
|
103
|
+
### Bedrock-only pricing
|
|
104
|
+
|
|
105
|
+
`BEDROCK_PRICING` is a table for `autotelTelemetry({ pricing })` covering the
|
|
106
|
+
models that exist only behind Bedrock: Nova, Llama, Mistral, DeepSeek, GLM.
|
|
107
|
+
Anthropic models are deliberately absent — Bedrock bills them at Anthropic's
|
|
108
|
+
rates and `autotel-genai` prices those by family already.
|
|
109
|
+
|
|
110
|
+
Keys match the way `autotel-genai/cost` resolves ids — exact, then prefix,
|
|
111
|
+
tried again after each region/vendor prefix is peeled — so
|
|
112
|
+
`eu.amazon.nova-pro-v1:0` resolves via `amazon.nova-pro`.
|
|
113
|
+
|
|
114
|
+
Approximate list prices at the time of writing; a convenience default, not a
|
|
115
|
+
billing source of truth. Spread and override what you use:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
autotelTelemetry({
|
|
119
|
+
pricing: {
|
|
120
|
+
...BEDROCK_PRICING,
|
|
121
|
+
'zai.glm-4.7-flash': { inputPer1M: 0.5, outputPer1M: 2 },
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## What you do not need this for
|
|
127
|
+
|
|
128
|
+
| Already arrives from | |
|
|
129
|
+
| ---------------------------------------- | -------------------------------------- |
|
|
130
|
+
| `gen_ai.provider.name = aws.bedrock` | `autotel-genai` provider normalisation |
|
|
131
|
+
| Anthropic model cost on Bedrock | `autotel-genai/cost` family pricing |
|
|
132
|
+
| Lambda spans, cold starts, X-Ray context | `autotel-aws/lambda` |
|
|
133
|
+
| Datadog / Langfuse ingestion | `autotel-backends`, `autotel-langfuse` |
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/model-id.ts
|
|
3
|
+
/**
|
|
4
|
+
* Bedrock model identifiers come in three spellings for the same model:
|
|
5
|
+
*
|
|
6
|
+
* anthropic.claude-sonnet-4-5-20250929-v1:0 foundation model id
|
|
7
|
+
* eu.anthropic.claude-sonnet-4-5-20250929-v1:0 cross-region inference profile
|
|
8
|
+
* arn:aws:bedrock:eu-west-1:123456789012:inference-profile/eu.anthropic.claude-sonnet-4-5-20250929-v1:0
|
|
9
|
+
*
|
|
10
|
+
* Dashboards, cost tables and model filters want the first. This parses any
|
|
11
|
+
* of them back to it and keeps the other two facts as their own fields.
|
|
12
|
+
*/
|
|
13
|
+
/** Cross-region inference-profile prefixes Bedrock issues. */
|
|
14
|
+
const REGION_PREFIXES = /* @__PURE__ */ new Set([
|
|
15
|
+
"us",
|
|
16
|
+
"eu",
|
|
17
|
+
"apac",
|
|
18
|
+
"global",
|
|
19
|
+
"jp",
|
|
20
|
+
"au",
|
|
21
|
+
"us-gov",
|
|
22
|
+
"ca"
|
|
23
|
+
]);
|
|
24
|
+
function parseBedrockModelId(raw) {
|
|
25
|
+
let id = raw;
|
|
26
|
+
let arn;
|
|
27
|
+
if (id.startsWith("arn:")) {
|
|
28
|
+
arn = id;
|
|
29
|
+
id = id.slice(id.lastIndexOf("/") + 1);
|
|
30
|
+
}
|
|
31
|
+
let inferenceProfileRegion;
|
|
32
|
+
const dot = id.indexOf(".");
|
|
33
|
+
if (dot > 0) {
|
|
34
|
+
const head = id.slice(0, dot);
|
|
35
|
+
if (REGION_PREFIXES.has(head) && id.indexOf(".", dot + 1) > dot) {
|
|
36
|
+
inferenceProfileRegion = head;
|
|
37
|
+
id = id.slice(dot + 1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const vendorDot = id.indexOf(".");
|
|
41
|
+
const vendor = vendorDot > 0 ? id.slice(0, vendorDot) : void 0;
|
|
42
|
+
return {
|
|
43
|
+
modelId: id,
|
|
44
|
+
inferenceProfileRegion,
|
|
45
|
+
arn,
|
|
46
|
+
vendor
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/pricing.ts
|
|
51
|
+
const BEDROCK_PRICING = {
|
|
52
|
+
"amazon.nova-micro": {
|
|
53
|
+
inputPer1M: .035,
|
|
54
|
+
outputPer1M: .14
|
|
55
|
+
},
|
|
56
|
+
"amazon.nova-lite": {
|
|
57
|
+
inputPer1M: .06,
|
|
58
|
+
outputPer1M: .24
|
|
59
|
+
},
|
|
60
|
+
"amazon.nova-pro": {
|
|
61
|
+
inputPer1M: .8,
|
|
62
|
+
outputPer1M: 3.2
|
|
63
|
+
},
|
|
64
|
+
"amazon.nova-premier": {
|
|
65
|
+
inputPer1M: 2.5,
|
|
66
|
+
outputPer1M: 12.5
|
|
67
|
+
},
|
|
68
|
+
"meta.llama3-1-8b-instruct": {
|
|
69
|
+
inputPer1M: .22,
|
|
70
|
+
outputPer1M: .22
|
|
71
|
+
},
|
|
72
|
+
"meta.llama3-1-70b-instruct": {
|
|
73
|
+
inputPer1M: .72,
|
|
74
|
+
outputPer1M: .72
|
|
75
|
+
},
|
|
76
|
+
"meta.llama3-3-70b-instruct": {
|
|
77
|
+
inputPer1M: .72,
|
|
78
|
+
outputPer1M: .72
|
|
79
|
+
},
|
|
80
|
+
"meta.llama4-scout-17b-instruct": {
|
|
81
|
+
inputPer1M: .17,
|
|
82
|
+
outputPer1M: .66
|
|
83
|
+
},
|
|
84
|
+
"meta.llama4-maverick-17b-instruct": {
|
|
85
|
+
inputPer1M: .24,
|
|
86
|
+
outputPer1M: .97
|
|
87
|
+
},
|
|
88
|
+
"mistral.mistral-large": {
|
|
89
|
+
inputPer1M: 2,
|
|
90
|
+
outputPer1M: 6
|
|
91
|
+
},
|
|
92
|
+
"mistral.pixtral-large": {
|
|
93
|
+
inputPer1M: 2,
|
|
94
|
+
outputPer1M: 6
|
|
95
|
+
},
|
|
96
|
+
"deepseek.r1": {
|
|
97
|
+
inputPer1M: 1.35,
|
|
98
|
+
outputPer1M: 5.4
|
|
99
|
+
},
|
|
100
|
+
"zai.glm-4.7-flash": {
|
|
101
|
+
inputPer1M: .6,
|
|
102
|
+
outputPer1M: 2.2
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/index.ts
|
|
107
|
+
/**
|
|
108
|
+
* Canonical attributes this processor reads. Spelled out rather than imported
|
|
109
|
+
* from `autotel-genai` so the package has no dependency beyond the OTel API.
|
|
110
|
+
*/
|
|
111
|
+
const GEN_AI_PROVIDER_NAME = "gen_ai.provider.name";
|
|
112
|
+
const GEN_AI_REQUEST_MODEL = "gen_ai.request.model";
|
|
113
|
+
const GEN_AI_RESPONSE_MODEL = "gen_ai.response.model";
|
|
114
|
+
const CLOUD_PROVIDER = "cloud.provider";
|
|
115
|
+
const CLOUD_REGION = "cloud.region";
|
|
116
|
+
/** The `gen_ai.provider.name` value the semantic conventions assign Bedrock. */
|
|
117
|
+
const AWS_BEDROCK_PROVIDER = "aws.bedrock";
|
|
118
|
+
/** Bedrock facts with no `gen_ai.*` equivalent. */
|
|
119
|
+
const AWS_BEDROCK = {
|
|
120
|
+
/** The model identifier exactly as the request named it, before normalisation. */
|
|
121
|
+
MODEL_ID_RAW: "aws.bedrock.model.id_raw",
|
|
122
|
+
/** Inference-profile ARN, when the request used one. */
|
|
123
|
+
MODEL_ARN: "aws.bedrock.model.arn",
|
|
124
|
+
/** Region group of a cross-region inference profile: `eu`, `us`, `global`… */
|
|
125
|
+
INFERENCE_PROFILE_REGION: "aws.bedrock.inference_profile.region",
|
|
126
|
+
/** Vendor segment of the foundation model id: `anthropic`, `amazon`, `meta`… */
|
|
127
|
+
MODEL_VENDOR: "aws.bedrock.model.vendor",
|
|
128
|
+
/**
|
|
129
|
+
* Bedrock's own stop reason (`end_turn`, `max_tokens`, `guardrail_intervened`,
|
|
130
|
+
* `malformed_tool_use`…). `gen_ai.response.finish_reasons` keeps the AI SDK's
|
|
131
|
+
* unified value, which folds several of these together.
|
|
132
|
+
*/
|
|
133
|
+
STOP_REASON: "aws.bedrock.stop_reason",
|
|
134
|
+
/** Canonical: the guardrail that assessed the call, from its trace. */
|
|
135
|
+
GUARDRAIL_ID: "aws.bedrock.guardrail.id",
|
|
136
|
+
/** Whether the guardrail stopped generation. A policy outcome, not an error. */
|
|
137
|
+
GUARDRAIL_INTERVENED: "aws.bedrock.guardrail.intervened"
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* A span processor that fills in the Bedrock-specific fields on the way out.
|
|
141
|
+
*
|
|
142
|
+
* It touches only spans whose `gen_ai.provider.name` is `aws.bedrock`, and on
|
|
143
|
+
* those it adds `aws.bedrock.*` and `cloud.*` attributes and, unless disabled,
|
|
144
|
+
* normalises the two model attributes. Every other span passes through
|
|
145
|
+
* untouched.
|
|
146
|
+
*/
|
|
147
|
+
function bedrockCompatibility(options = {}) {
|
|
148
|
+
const region = options.region ?? process.env.AWS_REGION;
|
|
149
|
+
const normalize = options.normalizeModel ?? true;
|
|
150
|
+
return {
|
|
151
|
+
onStart(_span, _context) {},
|
|
152
|
+
onEnd(span) {
|
|
153
|
+
const attributes = span.attributes;
|
|
154
|
+
if (attributes[GEN_AI_PROVIDER_NAME] !== "aws.bedrock") return;
|
|
155
|
+
attributes[CLOUD_PROVIDER] ??= "aws";
|
|
156
|
+
if (region) attributes[CLOUD_REGION] ??= region;
|
|
157
|
+
const raw = attributes[GEN_AI_REQUEST_MODEL];
|
|
158
|
+
if (typeof raw !== "string" || raw.length === 0) return;
|
|
159
|
+
const parsed = parseBedrockModelId(raw);
|
|
160
|
+
if (parsed.vendor) attributes[AWS_BEDROCK.MODEL_VENDOR] ??= parsed.vendor;
|
|
161
|
+
if (parsed.inferenceProfileRegion) attributes[AWS_BEDROCK.INFERENCE_PROFILE_REGION] ??= parsed.inferenceProfileRegion;
|
|
162
|
+
if (parsed.arn) attributes[AWS_BEDROCK.MODEL_ARN] ??= parsed.arn;
|
|
163
|
+
if (normalize && parsed.modelId !== raw) {
|
|
164
|
+
attributes[AWS_BEDROCK.MODEL_ID_RAW] ??= raw;
|
|
165
|
+
attributes[GEN_AI_REQUEST_MODEL] = parsed.modelId;
|
|
166
|
+
if (attributes[GEN_AI_RESPONSE_MODEL] === raw) attributes[GEN_AI_RESPONSE_MODEL] = parsed.modelId;
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
async forceFlush() {},
|
|
170
|
+
async shutdown() {}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Attributes for what Bedrock returned beside the standard response, for
|
|
175
|
+
* `autotelTelemetry({ providerAttributes })`: the stop reason in Bedrock's own
|
|
176
|
+
* words and, when the guardrail trace is on, which guardrail ran and whether
|
|
177
|
+
* it intervened. An intervention leaves the span's status alone: the request
|
|
178
|
+
* succeeded, the policy said no.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* registerTelemetry(
|
|
183
|
+
* autotelTelemetry({ pricing: BEDROCK_PRICING, providerAttributes: bedrockProviderAttributes }),
|
|
184
|
+
* );
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
function bedrockProviderAttributes(response) {
|
|
188
|
+
if (response.provider !== "aws.bedrock") return void 0;
|
|
189
|
+
const attributes = {};
|
|
190
|
+
if (response.rawFinishReason) {
|
|
191
|
+
attributes[AWS_BEDROCK.STOP_REASON] = response.rawFinishReason;
|
|
192
|
+
attributes[AWS_BEDROCK.GUARDRAIL_INTERVENED] = response.rawFinishReason === "guardrail_intervened";
|
|
193
|
+
}
|
|
194
|
+
const guardrail = (response.providerMetadata?.bedrock)?.trace?.guardrail;
|
|
195
|
+
const guardrailId = Object.keys({
|
|
196
|
+
...guardrail?.inputAssessment,
|
|
197
|
+
...guardrail?.outputAssessments
|
|
198
|
+
})[0];
|
|
199
|
+
if (guardrailId) attributes[AWS_BEDROCK.GUARDRAIL_ID] = guardrailId;
|
|
200
|
+
return attributes;
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
exports.AWS_BEDROCK = AWS_BEDROCK;
|
|
204
|
+
exports.AWS_BEDROCK_PROVIDER = AWS_BEDROCK_PROVIDER;
|
|
205
|
+
exports.BEDROCK_PRICING = BEDROCK_PRICING;
|
|
206
|
+
exports.bedrockCompatibility = bedrockCompatibility;
|
|
207
|
+
exports.bedrockProviderAttributes = bedrockProviderAttributes;
|
|
208
|
+
exports.parseBedrockModelId = parseBedrockModelId;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Attributes } from "@opentelemetry/api";
|
|
2
|
+
import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
import { ProviderResponseView } from "autotel-genai/observer";
|
|
4
|
+
//#region src/model-id.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Bedrock model identifiers come in three spellings for the same model:
|
|
7
|
+
*
|
|
8
|
+
* anthropic.claude-sonnet-4-5-20250929-v1:0 foundation model id
|
|
9
|
+
* eu.anthropic.claude-sonnet-4-5-20250929-v1:0 cross-region inference profile
|
|
10
|
+
* arn:aws:bedrock:eu-west-1:123456789012:inference-profile/eu.anthropic.claude-sonnet-4-5-20250929-v1:0
|
|
11
|
+
*
|
|
12
|
+
* Dashboards, cost tables and model filters want the first. This parses any
|
|
13
|
+
* of them back to it and keeps the other two facts as their own fields.
|
|
14
|
+
*/
|
|
15
|
+
interface ParsedBedrockModelId {
|
|
16
|
+
/** Foundation model id with any region prefix or ARN removed. */
|
|
17
|
+
modelId: string;
|
|
18
|
+
/** Region group of a cross-region inference profile (`eu`, `us`, `global`…). */
|
|
19
|
+
inferenceProfileRegion?: string;
|
|
20
|
+
/** The full ARN, when one was used. */
|
|
21
|
+
arn?: string;
|
|
22
|
+
/** Vendor segment of the id: `anthropic`, `amazon`, `meta`, `zai`… */
|
|
23
|
+
vendor?: string;
|
|
24
|
+
}
|
|
25
|
+
declare function parseBedrockModelId(raw: string): ParsedBedrockModelId;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/pricing.d.ts
|
|
28
|
+
/**
|
|
29
|
+
* On-demand Bedrock list prices, USD per 1M tokens, keyed the way
|
|
30
|
+
* `autotel-genai/cost` resolves them: an exact or prefix match on the
|
|
31
|
+
* foundation model id, tried again after each vendor/region prefix is
|
|
32
|
+
* peeled off. So `eu.amazon.nova-pro-v1:0` resolves via `amazon.nova-pro`.
|
|
33
|
+
*
|
|
34
|
+
* Anthropic models are deliberately absent: Bedrock bills them at the same
|
|
35
|
+
* rates as Anthropic direct, and `autotel-genai` already prices those by
|
|
36
|
+
* family. This table is for the models that only exist behind Bedrock.
|
|
37
|
+
*
|
|
38
|
+
* Approximate public prices at the time of writing (eu-west-1 / us-east-1
|
|
39
|
+
* on-demand). A convenience default, not a billing source of truth — check
|
|
40
|
+
* https://aws.amazon.com/bedrock/pricing/ and override what you use.
|
|
41
|
+
*/
|
|
42
|
+
interface BedrockModelPricing {
|
|
43
|
+
inputPer1M: number;
|
|
44
|
+
outputPer1M: number;
|
|
45
|
+
cachedInputPer1M?: number;
|
|
46
|
+
cacheWritePer1M?: number;
|
|
47
|
+
}
|
|
48
|
+
declare const BEDROCK_PRICING: Record<string, BedrockModelPricing>;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/index.d.ts
|
|
51
|
+
/** The `gen_ai.provider.name` value the semantic conventions assign Bedrock. */
|
|
52
|
+
declare const AWS_BEDROCK_PROVIDER = "aws.bedrock";
|
|
53
|
+
/** Bedrock facts with no `gen_ai.*` equivalent. */
|
|
54
|
+
declare const AWS_BEDROCK: {
|
|
55
|
+
/** The model identifier exactly as the request named it, before normalisation. */
|
|
56
|
+
readonly MODEL_ID_RAW: "aws.bedrock.model.id_raw";
|
|
57
|
+
/** Inference-profile ARN, when the request used one. */
|
|
58
|
+
readonly MODEL_ARN: "aws.bedrock.model.arn";
|
|
59
|
+
/** Region group of a cross-region inference profile: `eu`, `us`, `global`… */
|
|
60
|
+
readonly INFERENCE_PROFILE_REGION: "aws.bedrock.inference_profile.region";
|
|
61
|
+
/** Vendor segment of the foundation model id: `anthropic`, `amazon`, `meta`… */
|
|
62
|
+
readonly MODEL_VENDOR: "aws.bedrock.model.vendor";
|
|
63
|
+
/**
|
|
64
|
+
* Bedrock's own stop reason (`end_turn`, `max_tokens`, `guardrail_intervened`,
|
|
65
|
+
* `malformed_tool_use`…). `gen_ai.response.finish_reasons` keeps the AI SDK's
|
|
66
|
+
* unified value, which folds several of these together.
|
|
67
|
+
*/
|
|
68
|
+
readonly STOP_REASON: "aws.bedrock.stop_reason";
|
|
69
|
+
/** Canonical: the guardrail that assessed the call, from its trace. */
|
|
70
|
+
readonly GUARDRAIL_ID: "aws.bedrock.guardrail.id";
|
|
71
|
+
/** Whether the guardrail stopped generation. A policy outcome, not an error. */
|
|
72
|
+
readonly GUARDRAIL_INTERVENED: "aws.bedrock.guardrail.intervened";
|
|
73
|
+
};
|
|
74
|
+
interface BedrockCompatibilityOptions {
|
|
75
|
+
/**
|
|
76
|
+
* AWS region the calls are made in, recorded as `cloud.region`. Defaults to
|
|
77
|
+
* `AWS_REGION` from the environment (set on every Lambda); left off when
|
|
78
|
+
* neither is known.
|
|
79
|
+
*/
|
|
80
|
+
region?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Rewrite `gen_ai.request.model` / `gen_ai.response.model` to the foundation
|
|
83
|
+
* model id when the request used an inference profile or ARN. The original
|
|
84
|
+
* spelling is always kept in `aws.bedrock.model.id_raw`. Default `true`.
|
|
85
|
+
*/
|
|
86
|
+
normalizeModel?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A span processor that fills in the Bedrock-specific fields on the way out.
|
|
90
|
+
*
|
|
91
|
+
* It touches only spans whose `gen_ai.provider.name` is `aws.bedrock`, and on
|
|
92
|
+
* those it adds `aws.bedrock.*` and `cloud.*` attributes and, unless disabled,
|
|
93
|
+
* normalises the two model attributes. Every other span passes through
|
|
94
|
+
* untouched.
|
|
95
|
+
*/
|
|
96
|
+
declare function bedrockCompatibility(options?: BedrockCompatibilityOptions): SpanProcessor;
|
|
97
|
+
/**
|
|
98
|
+
* Attributes for what Bedrock returned beside the standard response, for
|
|
99
|
+
* `autotelTelemetry({ providerAttributes })`: the stop reason in Bedrock's own
|
|
100
|
+
* words and, when the guardrail trace is on, which guardrail ran and whether
|
|
101
|
+
* it intervened. An intervention leaves the span's status alone: the request
|
|
102
|
+
* succeeded, the policy said no.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* registerTelemetry(
|
|
107
|
+
* autotelTelemetry({ pricing: BEDROCK_PRICING, providerAttributes: bedrockProviderAttributes }),
|
|
108
|
+
* );
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function bedrockProviderAttributes(response: ProviderResponseView): Attributes | undefined;
|
|
112
|
+
//#endregion
|
|
113
|
+
export { AWS_BEDROCK, AWS_BEDROCK_PROVIDER, BEDROCK_PRICING, BedrockCompatibilityOptions, type BedrockModelPricing, type ParsedBedrockModelId, bedrockCompatibility, bedrockProviderAttributes, parseBedrockModelId };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Attributes } from "@opentelemetry/api";
|
|
2
|
+
import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
import { ProviderResponseView } from "autotel-genai/observer";
|
|
4
|
+
//#region src/model-id.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Bedrock model identifiers come in three spellings for the same model:
|
|
7
|
+
*
|
|
8
|
+
* anthropic.claude-sonnet-4-5-20250929-v1:0 foundation model id
|
|
9
|
+
* eu.anthropic.claude-sonnet-4-5-20250929-v1:0 cross-region inference profile
|
|
10
|
+
* arn:aws:bedrock:eu-west-1:123456789012:inference-profile/eu.anthropic.claude-sonnet-4-5-20250929-v1:0
|
|
11
|
+
*
|
|
12
|
+
* Dashboards, cost tables and model filters want the first. This parses any
|
|
13
|
+
* of them back to it and keeps the other two facts as their own fields.
|
|
14
|
+
*/
|
|
15
|
+
interface ParsedBedrockModelId {
|
|
16
|
+
/** Foundation model id with any region prefix or ARN removed. */
|
|
17
|
+
modelId: string;
|
|
18
|
+
/** Region group of a cross-region inference profile (`eu`, `us`, `global`…). */
|
|
19
|
+
inferenceProfileRegion?: string;
|
|
20
|
+
/** The full ARN, when one was used. */
|
|
21
|
+
arn?: string;
|
|
22
|
+
/** Vendor segment of the id: `anthropic`, `amazon`, `meta`, `zai`… */
|
|
23
|
+
vendor?: string;
|
|
24
|
+
}
|
|
25
|
+
declare function parseBedrockModelId(raw: string): ParsedBedrockModelId;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/pricing.d.ts
|
|
28
|
+
/**
|
|
29
|
+
* On-demand Bedrock list prices, USD per 1M tokens, keyed the way
|
|
30
|
+
* `autotel-genai/cost` resolves them: an exact or prefix match on the
|
|
31
|
+
* foundation model id, tried again after each vendor/region prefix is
|
|
32
|
+
* peeled off. So `eu.amazon.nova-pro-v1:0` resolves via `amazon.nova-pro`.
|
|
33
|
+
*
|
|
34
|
+
* Anthropic models are deliberately absent: Bedrock bills them at the same
|
|
35
|
+
* rates as Anthropic direct, and `autotel-genai` already prices those by
|
|
36
|
+
* family. This table is for the models that only exist behind Bedrock.
|
|
37
|
+
*
|
|
38
|
+
* Approximate public prices at the time of writing (eu-west-1 / us-east-1
|
|
39
|
+
* on-demand). A convenience default, not a billing source of truth — check
|
|
40
|
+
* https://aws.amazon.com/bedrock/pricing/ and override what you use.
|
|
41
|
+
*/
|
|
42
|
+
interface BedrockModelPricing {
|
|
43
|
+
inputPer1M: number;
|
|
44
|
+
outputPer1M: number;
|
|
45
|
+
cachedInputPer1M?: number;
|
|
46
|
+
cacheWritePer1M?: number;
|
|
47
|
+
}
|
|
48
|
+
declare const BEDROCK_PRICING: Record<string, BedrockModelPricing>;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/index.d.ts
|
|
51
|
+
/** The `gen_ai.provider.name` value the semantic conventions assign Bedrock. */
|
|
52
|
+
declare const AWS_BEDROCK_PROVIDER = "aws.bedrock";
|
|
53
|
+
/** Bedrock facts with no `gen_ai.*` equivalent. */
|
|
54
|
+
declare const AWS_BEDROCK: {
|
|
55
|
+
/** The model identifier exactly as the request named it, before normalisation. */
|
|
56
|
+
readonly MODEL_ID_RAW: "aws.bedrock.model.id_raw";
|
|
57
|
+
/** Inference-profile ARN, when the request used one. */
|
|
58
|
+
readonly MODEL_ARN: "aws.bedrock.model.arn";
|
|
59
|
+
/** Region group of a cross-region inference profile: `eu`, `us`, `global`… */
|
|
60
|
+
readonly INFERENCE_PROFILE_REGION: "aws.bedrock.inference_profile.region";
|
|
61
|
+
/** Vendor segment of the foundation model id: `anthropic`, `amazon`, `meta`… */
|
|
62
|
+
readonly MODEL_VENDOR: "aws.bedrock.model.vendor";
|
|
63
|
+
/**
|
|
64
|
+
* Bedrock's own stop reason (`end_turn`, `max_tokens`, `guardrail_intervened`,
|
|
65
|
+
* `malformed_tool_use`…). `gen_ai.response.finish_reasons` keeps the AI SDK's
|
|
66
|
+
* unified value, which folds several of these together.
|
|
67
|
+
*/
|
|
68
|
+
readonly STOP_REASON: "aws.bedrock.stop_reason";
|
|
69
|
+
/** Canonical: the guardrail that assessed the call, from its trace. */
|
|
70
|
+
readonly GUARDRAIL_ID: "aws.bedrock.guardrail.id";
|
|
71
|
+
/** Whether the guardrail stopped generation. A policy outcome, not an error. */
|
|
72
|
+
readonly GUARDRAIL_INTERVENED: "aws.bedrock.guardrail.intervened";
|
|
73
|
+
};
|
|
74
|
+
interface BedrockCompatibilityOptions {
|
|
75
|
+
/**
|
|
76
|
+
* AWS region the calls are made in, recorded as `cloud.region`. Defaults to
|
|
77
|
+
* `AWS_REGION` from the environment (set on every Lambda); left off when
|
|
78
|
+
* neither is known.
|
|
79
|
+
*/
|
|
80
|
+
region?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Rewrite `gen_ai.request.model` / `gen_ai.response.model` to the foundation
|
|
83
|
+
* model id when the request used an inference profile or ARN. The original
|
|
84
|
+
* spelling is always kept in `aws.bedrock.model.id_raw`. Default `true`.
|
|
85
|
+
*/
|
|
86
|
+
normalizeModel?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A span processor that fills in the Bedrock-specific fields on the way out.
|
|
90
|
+
*
|
|
91
|
+
* It touches only spans whose `gen_ai.provider.name` is `aws.bedrock`, and on
|
|
92
|
+
* those it adds `aws.bedrock.*` and `cloud.*` attributes and, unless disabled,
|
|
93
|
+
* normalises the two model attributes. Every other span passes through
|
|
94
|
+
* untouched.
|
|
95
|
+
*/
|
|
96
|
+
declare function bedrockCompatibility(options?: BedrockCompatibilityOptions): SpanProcessor;
|
|
97
|
+
/**
|
|
98
|
+
* Attributes for what Bedrock returned beside the standard response, for
|
|
99
|
+
* `autotelTelemetry({ providerAttributes })`: the stop reason in Bedrock's own
|
|
100
|
+
* words and, when the guardrail trace is on, which guardrail ran and whether
|
|
101
|
+
* it intervened. An intervention leaves the span's status alone: the request
|
|
102
|
+
* succeeded, the policy said no.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* registerTelemetry(
|
|
107
|
+
* autotelTelemetry({ pricing: BEDROCK_PRICING, providerAttributes: bedrockProviderAttributes }),
|
|
108
|
+
* );
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function bedrockProviderAttributes(response: ProviderResponseView): Attributes | undefined;
|
|
112
|
+
//#endregion
|
|
113
|
+
export { AWS_BEDROCK, AWS_BEDROCK_PROVIDER, BEDROCK_PRICING, BedrockCompatibilityOptions, type BedrockModelPricing, type ParsedBedrockModelId, bedrockCompatibility, bedrockProviderAttributes, parseBedrockModelId };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
//#region src/model-id.ts
|
|
2
|
+
/**
|
|
3
|
+
* Bedrock model identifiers come in three spellings for the same model:
|
|
4
|
+
*
|
|
5
|
+
* anthropic.claude-sonnet-4-5-20250929-v1:0 foundation model id
|
|
6
|
+
* eu.anthropic.claude-sonnet-4-5-20250929-v1:0 cross-region inference profile
|
|
7
|
+
* arn:aws:bedrock:eu-west-1:123456789012:inference-profile/eu.anthropic.claude-sonnet-4-5-20250929-v1:0
|
|
8
|
+
*
|
|
9
|
+
* Dashboards, cost tables and model filters want the first. This parses any
|
|
10
|
+
* of them back to it and keeps the other two facts as their own fields.
|
|
11
|
+
*/
|
|
12
|
+
/** Cross-region inference-profile prefixes Bedrock issues. */
|
|
13
|
+
const REGION_PREFIXES = /* @__PURE__ */ new Set([
|
|
14
|
+
"us",
|
|
15
|
+
"eu",
|
|
16
|
+
"apac",
|
|
17
|
+
"global",
|
|
18
|
+
"jp",
|
|
19
|
+
"au",
|
|
20
|
+
"us-gov",
|
|
21
|
+
"ca"
|
|
22
|
+
]);
|
|
23
|
+
function parseBedrockModelId(raw) {
|
|
24
|
+
let id = raw;
|
|
25
|
+
let arn;
|
|
26
|
+
if (id.startsWith("arn:")) {
|
|
27
|
+
arn = id;
|
|
28
|
+
id = id.slice(id.lastIndexOf("/") + 1);
|
|
29
|
+
}
|
|
30
|
+
let inferenceProfileRegion;
|
|
31
|
+
const dot = id.indexOf(".");
|
|
32
|
+
if (dot > 0) {
|
|
33
|
+
const head = id.slice(0, dot);
|
|
34
|
+
if (REGION_PREFIXES.has(head) && id.indexOf(".", dot + 1) > dot) {
|
|
35
|
+
inferenceProfileRegion = head;
|
|
36
|
+
id = id.slice(dot + 1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const vendorDot = id.indexOf(".");
|
|
40
|
+
const vendor = vendorDot > 0 ? id.slice(0, vendorDot) : void 0;
|
|
41
|
+
return {
|
|
42
|
+
modelId: id,
|
|
43
|
+
inferenceProfileRegion,
|
|
44
|
+
arn,
|
|
45
|
+
vendor
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/pricing.ts
|
|
50
|
+
const BEDROCK_PRICING = {
|
|
51
|
+
"amazon.nova-micro": {
|
|
52
|
+
inputPer1M: .035,
|
|
53
|
+
outputPer1M: .14
|
|
54
|
+
},
|
|
55
|
+
"amazon.nova-lite": {
|
|
56
|
+
inputPer1M: .06,
|
|
57
|
+
outputPer1M: .24
|
|
58
|
+
},
|
|
59
|
+
"amazon.nova-pro": {
|
|
60
|
+
inputPer1M: .8,
|
|
61
|
+
outputPer1M: 3.2
|
|
62
|
+
},
|
|
63
|
+
"amazon.nova-premier": {
|
|
64
|
+
inputPer1M: 2.5,
|
|
65
|
+
outputPer1M: 12.5
|
|
66
|
+
},
|
|
67
|
+
"meta.llama3-1-8b-instruct": {
|
|
68
|
+
inputPer1M: .22,
|
|
69
|
+
outputPer1M: .22
|
|
70
|
+
},
|
|
71
|
+
"meta.llama3-1-70b-instruct": {
|
|
72
|
+
inputPer1M: .72,
|
|
73
|
+
outputPer1M: .72
|
|
74
|
+
},
|
|
75
|
+
"meta.llama3-3-70b-instruct": {
|
|
76
|
+
inputPer1M: .72,
|
|
77
|
+
outputPer1M: .72
|
|
78
|
+
},
|
|
79
|
+
"meta.llama4-scout-17b-instruct": {
|
|
80
|
+
inputPer1M: .17,
|
|
81
|
+
outputPer1M: .66
|
|
82
|
+
},
|
|
83
|
+
"meta.llama4-maverick-17b-instruct": {
|
|
84
|
+
inputPer1M: .24,
|
|
85
|
+
outputPer1M: .97
|
|
86
|
+
},
|
|
87
|
+
"mistral.mistral-large": {
|
|
88
|
+
inputPer1M: 2,
|
|
89
|
+
outputPer1M: 6
|
|
90
|
+
},
|
|
91
|
+
"mistral.pixtral-large": {
|
|
92
|
+
inputPer1M: 2,
|
|
93
|
+
outputPer1M: 6
|
|
94
|
+
},
|
|
95
|
+
"deepseek.r1": {
|
|
96
|
+
inputPer1M: 1.35,
|
|
97
|
+
outputPer1M: 5.4
|
|
98
|
+
},
|
|
99
|
+
"zai.glm-4.7-flash": {
|
|
100
|
+
inputPer1M: .6,
|
|
101
|
+
outputPer1M: 2.2
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/index.ts
|
|
106
|
+
/**
|
|
107
|
+
* Canonical attributes this processor reads. Spelled out rather than imported
|
|
108
|
+
* from `autotel-genai` so the package has no dependency beyond the OTel API.
|
|
109
|
+
*/
|
|
110
|
+
const GEN_AI_PROVIDER_NAME = "gen_ai.provider.name";
|
|
111
|
+
const GEN_AI_REQUEST_MODEL = "gen_ai.request.model";
|
|
112
|
+
const GEN_AI_RESPONSE_MODEL = "gen_ai.response.model";
|
|
113
|
+
const CLOUD_PROVIDER = "cloud.provider";
|
|
114
|
+
const CLOUD_REGION = "cloud.region";
|
|
115
|
+
/** The `gen_ai.provider.name` value the semantic conventions assign Bedrock. */
|
|
116
|
+
const AWS_BEDROCK_PROVIDER = "aws.bedrock";
|
|
117
|
+
/** Bedrock facts with no `gen_ai.*` equivalent. */
|
|
118
|
+
const AWS_BEDROCK = {
|
|
119
|
+
/** The model identifier exactly as the request named it, before normalisation. */
|
|
120
|
+
MODEL_ID_RAW: "aws.bedrock.model.id_raw",
|
|
121
|
+
/** Inference-profile ARN, when the request used one. */
|
|
122
|
+
MODEL_ARN: "aws.bedrock.model.arn",
|
|
123
|
+
/** Region group of a cross-region inference profile: `eu`, `us`, `global`… */
|
|
124
|
+
INFERENCE_PROFILE_REGION: "aws.bedrock.inference_profile.region",
|
|
125
|
+
/** Vendor segment of the foundation model id: `anthropic`, `amazon`, `meta`… */
|
|
126
|
+
MODEL_VENDOR: "aws.bedrock.model.vendor",
|
|
127
|
+
/**
|
|
128
|
+
* Bedrock's own stop reason (`end_turn`, `max_tokens`, `guardrail_intervened`,
|
|
129
|
+
* `malformed_tool_use`…). `gen_ai.response.finish_reasons` keeps the AI SDK's
|
|
130
|
+
* unified value, which folds several of these together.
|
|
131
|
+
*/
|
|
132
|
+
STOP_REASON: "aws.bedrock.stop_reason",
|
|
133
|
+
/** Canonical: the guardrail that assessed the call, from its trace. */
|
|
134
|
+
GUARDRAIL_ID: "aws.bedrock.guardrail.id",
|
|
135
|
+
/** Whether the guardrail stopped generation. A policy outcome, not an error. */
|
|
136
|
+
GUARDRAIL_INTERVENED: "aws.bedrock.guardrail.intervened"
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* A span processor that fills in the Bedrock-specific fields on the way out.
|
|
140
|
+
*
|
|
141
|
+
* It touches only spans whose `gen_ai.provider.name` is `aws.bedrock`, and on
|
|
142
|
+
* those it adds `aws.bedrock.*` and `cloud.*` attributes and, unless disabled,
|
|
143
|
+
* normalises the two model attributes. Every other span passes through
|
|
144
|
+
* untouched.
|
|
145
|
+
*/
|
|
146
|
+
function bedrockCompatibility(options = {}) {
|
|
147
|
+
const region = options.region ?? process.env.AWS_REGION;
|
|
148
|
+
const normalize = options.normalizeModel ?? true;
|
|
149
|
+
return {
|
|
150
|
+
onStart(_span, _context) {},
|
|
151
|
+
onEnd(span) {
|
|
152
|
+
const attributes = span.attributes;
|
|
153
|
+
if (attributes[GEN_AI_PROVIDER_NAME] !== "aws.bedrock") return;
|
|
154
|
+
attributes[CLOUD_PROVIDER] ??= "aws";
|
|
155
|
+
if (region) attributes[CLOUD_REGION] ??= region;
|
|
156
|
+
const raw = attributes[GEN_AI_REQUEST_MODEL];
|
|
157
|
+
if (typeof raw !== "string" || raw.length === 0) return;
|
|
158
|
+
const parsed = parseBedrockModelId(raw);
|
|
159
|
+
if (parsed.vendor) attributes[AWS_BEDROCK.MODEL_VENDOR] ??= parsed.vendor;
|
|
160
|
+
if (parsed.inferenceProfileRegion) attributes[AWS_BEDROCK.INFERENCE_PROFILE_REGION] ??= parsed.inferenceProfileRegion;
|
|
161
|
+
if (parsed.arn) attributes[AWS_BEDROCK.MODEL_ARN] ??= parsed.arn;
|
|
162
|
+
if (normalize && parsed.modelId !== raw) {
|
|
163
|
+
attributes[AWS_BEDROCK.MODEL_ID_RAW] ??= raw;
|
|
164
|
+
attributes[GEN_AI_REQUEST_MODEL] = parsed.modelId;
|
|
165
|
+
if (attributes[GEN_AI_RESPONSE_MODEL] === raw) attributes[GEN_AI_RESPONSE_MODEL] = parsed.modelId;
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
async forceFlush() {},
|
|
169
|
+
async shutdown() {}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Attributes for what Bedrock returned beside the standard response, for
|
|
174
|
+
* `autotelTelemetry({ providerAttributes })`: the stop reason in Bedrock's own
|
|
175
|
+
* words and, when the guardrail trace is on, which guardrail ran and whether
|
|
176
|
+
* it intervened. An intervention leaves the span's status alone: the request
|
|
177
|
+
* succeeded, the policy said no.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* registerTelemetry(
|
|
182
|
+
* autotelTelemetry({ pricing: BEDROCK_PRICING, providerAttributes: bedrockProviderAttributes }),
|
|
183
|
+
* );
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
function bedrockProviderAttributes(response) {
|
|
187
|
+
if (response.provider !== "aws.bedrock") return void 0;
|
|
188
|
+
const attributes = {};
|
|
189
|
+
if (response.rawFinishReason) {
|
|
190
|
+
attributes[AWS_BEDROCK.STOP_REASON] = response.rawFinishReason;
|
|
191
|
+
attributes[AWS_BEDROCK.GUARDRAIL_INTERVENED] = response.rawFinishReason === "guardrail_intervened";
|
|
192
|
+
}
|
|
193
|
+
const guardrail = (response.providerMetadata?.bedrock)?.trace?.guardrail;
|
|
194
|
+
const guardrailId = Object.keys({
|
|
195
|
+
...guardrail?.inputAssessment,
|
|
196
|
+
...guardrail?.outputAssessments
|
|
197
|
+
})[0];
|
|
198
|
+
if (guardrailId) attributes[AWS_BEDROCK.GUARDRAIL_ID] = guardrailId;
|
|
199
|
+
return attributes;
|
|
200
|
+
}
|
|
201
|
+
//#endregion
|
|
202
|
+
export { AWS_BEDROCK, AWS_BEDROCK_PROVIDER, BEDROCK_PRICING, bedrockCompatibility, bedrockProviderAttributes, parseBedrockModelId };
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "autotel-bedrock",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Amazon Bedrock facts for autotel's canonical gen_ai.* spans: model-id normalisation for inference profiles and ARNs, cloud.region, and a Bedrock price table",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"NOTICE"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@opentelemetry/api": "^1.9.1"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@opentelemetry/sdk-trace-base": ">=2.0.0",
|
|
27
|
+
"autotel-genai": ">=1.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@opentelemetry/sdk-trace-base": "^2.11.0",
|
|
31
|
+
"@types/node": "^26.1.2",
|
|
32
|
+
"autotel-genai": "0.13.1",
|
|
33
|
+
"tsdown": "^0.22.14",
|
|
34
|
+
"typescript": "^6.0.3",
|
|
35
|
+
"vitest": "^4.1.10"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"opentelemetry",
|
|
39
|
+
"otel",
|
|
40
|
+
"bedrock",
|
|
41
|
+
"aws",
|
|
42
|
+
"llm",
|
|
43
|
+
"gen_ai",
|
|
44
|
+
"tracing",
|
|
45
|
+
"observability",
|
|
46
|
+
"autotel"
|
|
47
|
+
],
|
|
48
|
+
"license": "Apache-2.0",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "https://github.com/jagreehal/autotel",
|
|
52
|
+
"directory": "packages/autotel-bedrock"
|
|
53
|
+
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"autotel-genai": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsdown",
|
|
61
|
+
"dev": "tsdown --watch",
|
|
62
|
+
"type-check": "tsc --noEmit",
|
|
63
|
+
"lint": "eslint src",
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"clean": "rimraf dist"
|
|
66
|
+
}
|
|
67
|
+
}
|