Skip to content

Commit d93e37d

Browse files
remove sentry from SDK, only use in CLI
1 parent f551ced commit d93e37d

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codesandbox/sdk",
3-
"version": "2.0.0-rc.10",
3+
"version": "2.0.0-rc.11",
44
"description": "The CodeSandbox SDK",
55
"author": "CodeSandbox",
66
"license": "MIT",

src/bin/commands/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as readline from "readline";
44
import { type Client } from "@hey-api/client-fetch";
55
import ora from "ora";
66
import type * as yargs from "yargs";
7-
7+
import { instrumentedFetch } from "../utils/sentry";
88
import { VMTier, CodeSandbox, Sandbox, SandboxClient } from "@codesandbox/sdk";
99

1010
import {
@@ -100,7 +100,7 @@ export const buildCommand: yargs.CommandModule<
100100

101101
handler: async (argv) => {
102102
const apiKey = getInferredApiKey();
103-
const apiClient: Client = createApiClient("CLI", apiKey);
103+
const apiClient: Client = createApiClient(apiKey, {}, instrumentedFetch);
104104
const sdk = new CodeSandbox(apiKey);
105105
const sandboxTier = argv.vmTier
106106
? VMTier.fromName(argv.vmTier)
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ if (!Sentry.isInitialized()) {
88
});
99
}
1010

11-
export async function instrumentedFetch(
12-
request: Request,
13-
client: "SDK" | "CLI"
14-
) {
11+
export async function instrumentedFetch(request: Request) {
1512
// We are cloning the request to be able to read its body on errors
1613
const res = await fetch(request.clone());
1714

@@ -24,7 +21,7 @@ export async function instrumentedFetch(
2421
? await new Response(request.body).text()
2522
: undefined,
2623
body: await res.clone().text(),
27-
client,
24+
client: "SDK-CLI",
2825
method: request.method,
2926
url: request.url,
3027
status: res.status,

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class CodeSandbox {
2525

2626
constructor(apiToken?: string, opts: ClientOpts = {}) {
2727
const apiKey = apiToken || getInferredApiKey();
28-
const apiClient = createApiClient("SDK", apiKey, opts);
28+
const apiClient = createApiClient(apiKey, opts);
2929

3030
this.sandboxes = new Sandboxes(apiClient);
3131
this.hosts = new HostTokens(apiClient);

src/utils/api.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import {
99
createConfig,
1010
} from "@hey-api/client-fetch";
1111
import { getInferredBaseUrl } from "./constants";
12-
import { instrumentedFetch } from "./sentry";
1312

14-
async function enhanceFetch(request: Request, client: "SDK" | "CLI") {
13+
async function enhanceFetch(
14+
request: Request,
15+
instrumentation?: (request: Request) => Promise<Response>
16+
) {
1517
// Clone the request to modify headers
1618
const headers = new Headers(request.headers);
1719
const existingUserAgent = headers.get("User-Agent") || "";
@@ -25,24 +27,29 @@ async function enhanceFetch(request: Request, client: "SDK" | "CLI") {
2527
}`.trim()
2628
);
2729

28-
// Create new request with updated headers
29-
return instrumentedFetch(
30-
new Request(request, {
31-
headers,
32-
}),
33-
client
34-
);
30+
// Create new request with updated headers and optionally add instrumentation
31+
return instrumentation
32+
? instrumentation(
33+
new Request(request, {
34+
headers,
35+
})
36+
)
37+
: fetch(
38+
new Request(request, {
39+
headers,
40+
})
41+
);
3542
}
3643

3744
export function createApiClient(
38-
client: "SDK" | "CLI",
3945
apiKey: string,
40-
config: Config = {}
46+
config: Config = {},
47+
instrumentation?: (request: Request) => Promise<Response>
4148
) {
4249
return createClient(
4350
createConfig({
4451
baseUrl: config.baseUrl || getInferredBaseUrl(apiKey),
45-
fetch: (request) => enhanceFetch(request, client),
52+
fetch: (request) => enhanceFetch(request, instrumentation),
4653
...config,
4754
headers: {
4855
Authorization: `Bearer ${apiKey}`,

0 commit comments

Comments
 (0)