diff --git a/.changeset/real-students-hide.md b/.changeset/real-students-hide.md deleted file mode 100644 index 99b72e6..0000000 --- a/.changeset/real-students-hide.md +++ /dev/null @@ -1,57 +0,0 @@ ---- -"opentelemetry-sdk-workers": minor ---- - -Add support for fetch-based bindings. - -You can now trace any `fetch`-based bindings like Service Bindings or Durable Objects. -To use this support, you can pass in the Env to the third argument when creating the Workers SDK and access bindings via `sdk.env.`. - -For example, say you have an authentication service bound as `auth`: - -```typescript -/* Required to patch missing performance API in Cloudflare Workers. */ -import "opentelemetry-sdk-workers/performance"; -import { WorkersSDK } from "opentelemetry-sdk-workers"; - -export interface Env { - OTLP_ENDPOINT: string; - - /*** - * Authentication Service - */ - AUTH: Fetcher /* Type available from @cloudflare/workers-types */; -} - - -export default { - async fetch( - request: Request, - env: Env, - ctx: ExecutionContext - ): Promise { - const sdk = new WorkersSDK(request, ctx, env, { - /* This is the service.name */ - service: "worker", - /* The OTLP/HTTP JSON Endpoint to send traces */ - endpoint: env.OTLP_ENDPOINT - }); - - try { - - const authResponse = await sdk.env.AUTH.fetch(request); - if (!authResponse.ok) { - return sdk.sendResponse(authResponse); - } - - const response = await sdk.fetch("https://httpbin.org/headers/"); - return sdk.sendResponse(response); - } catch (ex) { - sdk.captureException(ex); - } - }, -}; -``` - -> **Note** -> When using TypeScript, you must provide the Environment type with bindings inheriting from the `Fetcher` type in the `@cloudflare/worker-types` in order for them to be available on `sdk.env`. diff --git a/packages/opentelemetry-sdk-workers/CHANGELOG.md b/packages/opentelemetry-sdk-workers/CHANGELOG.md index 4c549ab..a62ebb4 100644 --- a/packages/opentelemetry-sdk-workers/CHANGELOG.md +++ b/packages/opentelemetry-sdk-workers/CHANGELOG.md @@ -1,5 +1,61 @@ # opentelemetry-sdk-workers +## 0.6.0 + +### Minor Changes + +- [#21](https://github.com/RichiCoder1/opentelemetry-sdk-workers/pull/21) [`8391689`](https://github.com/RichiCoder1/opentelemetry-sdk-workers/commit/839168910f689368f463dd4d2ea4b2bf9eecb9c6) Thanks [@RichiCoder1](https://github.com/RichiCoder1)! - Add support for fetch-based bindings. + + You can now trace any `fetch`-based bindings like Service Bindings or Durable Objects. + To use this support, you can pass in the Env to the third argument when creating the Workers SDK and access bindings via `sdk.env.`. + + For example, say you have an authentication service bound as `auth`: + + ```typescript + /* Required to patch missing performance API in Cloudflare Workers. */ + import "opentelemetry-sdk-workers/performance"; + import { WorkersSDK } from "opentelemetry-sdk-workers"; + + export interface Env { + OTLP_ENDPOINT: string; + + /*** + * Authentication Service + */ + AUTH: Fetcher /* Type available from @cloudflare/workers-types */; + } + + export default { + async fetch( + request: Request, + env: Env, + ctx: ExecutionContext + ): Promise { + const sdk = new WorkersSDK(request, ctx, env, { + /* This is the service.name */ + service: "worker", + /* The OTLP/HTTP JSON Endpoint to send traces */ + endpoint: env.OTLP_ENDPOINT, + }); + + try { + const authResponse = await sdk.env.AUTH.fetch(request); + if (!authResponse.ok) { + return sdk.sendResponse(authResponse); + } + + const response = await sdk.fetch("https://httpbin.org/headers/"); + return sdk.sendResponse(response); + } catch (ex) { + sdk.captureException(ex); + } + }, + }; + ``` + + > **Note** + > When using TypeScript, you must provide the Environment type with bindings inheriting from the `Fetcher` type in the `@cloudflare/worker-types` in order for them to be available on `sdk.env`. + ## 0.5.0 ### Minor Changes diff --git a/packages/opentelemetry-sdk-workers/package.json b/packages/opentelemetry-sdk-workers/package.json index 48f77eb..0860554 100644 --- a/packages/opentelemetry-sdk-workers/package.json +++ b/packages/opentelemetry-sdk-workers/package.json @@ -1,6 +1,6 @@ { "name": "opentelemetry-sdk-workers", - "version": "0.5.0", + "version": "0.6.0", "description": "Open Telemetry Cloudflare Workers Library. Provides a basic sdk for instrumenting workers.", "module": "dist/index.mjs", "exports": {