Skip to content

Commit

Permalink
Fix detecting of browser rendering + ai binding
Browse files Browse the repository at this point in the history
  • Loading branch information
evanderkoogh committed Nov 1, 2023
1 parent 3329401 commit 2d370cb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"nervous-kids-guess",
"new-gifts-repair",
"smooth-vans-know",
"strong-monkeys-film",
"two-oranges-peel"
]
}
5 changes: 5 additions & 0 deletions .changeset/strong-monkeys-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@microlabs/otel-cf-workers': patch
---

Browser Rendering + AI binding send invalid URLs. Disable auto-instrumentation for now.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @microlabs/otel-cf-workers

## 1.0.0-rc.20

### Patch Changes

- Browser Rendering + AI binding send invalid URLs. Disable auto-instrumentation for now.

## 1.0.0-rc.19

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microlabs/otel-cf-workers",
"version": "1.0.0-rc.19",
"version": "1.0.0-rc.20",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
Expand Down
12 changes: 2 additions & 10 deletions src/instrumentation/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,6 @@ export function createFetchHandler(fetchFn: FetchHandler, initialiser: Initialis
return wrap(fetchFn, fetchHandler)
}

function tryRequest(arg1: unknown, arg2: unknown): Request | undefined {
try {
return new Request(arg1 as RequestInfo, arg2 as RequestInit)
} catch (err) {
return undefined
}
}

type getFetchConfig = (config: ResolvedTraceConfig) => FetcherConfig
export function instrumentClientFetch(
fetchFn: Fetcher['fetch'],
Expand All @@ -208,8 +200,8 @@ export function instrumentClientFetch(
): Fetcher['fetch'] {
const handler: ProxyHandler<typeof fetch> = {
apply: (target, thisArg, argArray): ReturnType<typeof fetch> => {
const request = tryRequest(argArray[0], argArray[1])
if (!request) {
const request = new Request(argArray[0], argArray[1])
if (!request.url.startsWith('http')) {
return Reflect.apply(target, thisArg, argArray)
}

Expand Down

0 comments on commit 2d370cb

Please sign in to comment.