Skip to content

Commit c16f6ba

Browse files
authored
feat: Add instrumentation for @huggingface/inference (#1807)
Resolves: #1806
1 parent 6d78bdc commit c16f6ba

41 files changed

Lines changed: 4895 additions & 9 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.agents/skills/instrumentation/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Map the change before editing:
2828
- Support both auto-instrumentation and manual instrumentation. Auto-instrumentation does not cover every environment, loader, or framework.
2929
- For orchestrion auto-instrumentation, prefer targeting public API functions. Instrumenting internal helpers is more likely to break across library versions.
3030
- Auto and manual paths should share logic. Prefer both paths emitting the same tracing-channel events, with provider plugins converting those events into spans/logs/errors. Manual wrappers should not directly emit observability data.
31+
- Reuse shared repo utilities before introducing local helpers. Check `js/util/index.ts`, neighboring instrumentation files, and existing plugins/wrappers for utilities like `isObject`, merge helpers, and sanitizers before adding ad hoc replacements.
3132
- If a public instrumentation surface changes, check whether the export surface also needs updates in `js/src/instrumentation/index.ts` or `js/src/exports.ts`.
3233
- Preserve async context propagation. Changes around tracing channels, stream patching, or loader hooks must keep the current span context across awaits and stream consumption.
3334
- Maintain isomorphic behavior. Node and browser/bundled paths must use compatible channel implementations and avoid channel-registry mismatches.

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ ANTHROPIC_API_KEY=
44
GEMINI_API_KEY=
55
OPENROUTER_API_KEY=
66
MISTRAL_API_KEY=
7+
HUGGINGFACE_API_KEY=
78
COHERE_API_KEY=

.github/workflows/e2e-canary.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
3939
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
4040
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
41+
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
4142
run: pnpm test:e2e:canary
4243
- name: Create or update nightly canary issue
4344
if: ${{ failure() && github.event_name == 'schedule' }}

.github/workflows/integration-tests.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
3232
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
3333
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
34+
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
3435
steps:
3536
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
3637
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
@@ -60,6 +61,7 @@ jobs:
6061
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
6162
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
6263
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
64+
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
6365
steps:
6466
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
6567
- uses: denoland/setup-deno@ff4860f9d7236f320afa0f82b7e6457384805d05 # v2.0.4
@@ -110,6 +112,7 @@ jobs:
110112
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
111113
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
112114
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
115+
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
113116
steps:
114117
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
115118
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0

e2e/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Non-hermetic scenarios require provider credentials in addition to the mock Brai
117117
- `GEMINI_API_KEY` or `GOOGLE_API_KEY`
118118
- `OPENROUTER_API_KEY`
119119
- `MISTRAL_API_KEY`
120+
- `HUGGINGFACE_API_KEY`
120121
- `COHERE_API_KEY`
121122

122123
`claude-agent-sdk-instrumentation` also uses `ANTHROPIC_API_KEY`, because it runs the real Claude Agent SDK against Anthropic in the same style as the existing live Anthropic wrapper coverage.

e2e/config/pr-comment-scenarios.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
{ "variantKey": "google-genai-v1460", "label": "v1.46.0" }
3434
]
3535
},
36+
{
37+
"scenarioDirName": "huggingface-instrumentation",
38+
"label": "HuggingFace Instrumentation",
39+
"metadataScenario": "huggingface-instrumentation",
40+
"variants": [
41+
{ "variantKey": "huggingface-v281", "label": "v2.8.1" },
42+
{ "variantKey": "huggingface-v3150", "label": "v3.15.0" },
43+
{ "variantKey": "huggingface-v41315", "label": "v4.13.15" }
44+
]
45+
},
3646
{
3747
"scenarioDirName": "mistral-instrumentation",
3848
"label": "Mistral Instrumentation",

e2e/helpers/scenario-installer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ const CANARY_MODE_ENV = "BRAINTRUST_E2E_MODE";
2121
const INSTALL_SECRET_ENV_VARS = [
2222
"ANTHROPIC_API_KEY",
2323
"BRAINTRUST_API_KEY",
24+
"COHERE_API_KEY",
2425
"GEMINI_API_KEY",
2526
"GITHUB_TOKEN",
2627
"GH_TOKEN",
28+
"HUGGINGFACE_API_KEY",
2729
"OPENAI_API_KEY",
2830
"OPENROUTER_API_KEY",
2931
"MISTRAL_API_KEY",
30-
"COHERE_API_KEY",
3132
] as const;
3233

3334
const cleanupDirs = new Set<string>();

0 commit comments

Comments
 (0)