getsentry / getsentry/sentry-javascript

Add tunneling option to @sentry/astro

Đang mở
#10,309 4 bình luận 0 reaction 1 người được giao Được @florian-lefebvre nhận Xem trên GitHub
Astro Improvement
Ngôn ngữ chính
TypeScript
Star
8.7k
Fork
1.8k
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
515

Mô tả

### Problem Statement

I think the Next package has an option for tunneling, it would be great to have the same for Astro

### Solution Brainstorm

Back when I had a look at the docs, there was a snippet with how to create a tunnel endpoint in PHP. Closest thing I find now is https://docs.sentry.io/platforms/javascript/troubleshooting/#using-the-tunnel-option.

Anyway, it seems fairly easy with the `injectRoute` utility. Here is what I've done for a project of mine:

```ts
// src/pages/sy/[...params].ts

import type { APIContext } from "astro";

export const prerender = false;

export async function POST({ request }: APIContext) {
const body = await request.text();

let payload: {
sent_at: string;
sdk: { name: string; version: string };
dsn: string;
};

try {
payload = JSON.parse(body.split("\n")[0]);
} catch (err) {
console.error(err);
return new Response(null, { status: 400 });
}

if (!payload.dsn) {
return new Response("Invalid request", { status: 400 });
}

const dsn = new URL(payload.dsn);
const projectID = dsn.pathname.replace(/\//g, "");

if (projectID !== import.meta.env.SECRET_SENTRY_PROJECT_ID) {
return new Response("Invalid request", { status: 400 });
}

await fetch(`https://sentry.io/api/${projectID}/envelope/`, {
method: "POST",
headers: {
"Content-type": "application/x-sentry-envelope",
},
body: JSON.stringify(payload),
});

return new Response(null, { status: 200 });
}
```
It's not always working so something is probably off. I can contribute this if you can help fix the endpoint logic itself

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.