Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 13 additions & 89 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config = {
dynamic: 180,
static: 180,
},
nodeMiddleware: true,
serverActions: {
bodySizeLimit: '5mb',
},
Expand All @@ -20,7 +21,6 @@ const config = {
fullUrl: true,
},
},
serverExternalPackages: ['pino', 'pino-loki'],
trailingSlash: false,
webpack: (config) => {
config.module.rules.push({
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/auto-instrumentations-node": "^0.62.1",
"@opentelemetry/exporter-logs-otlp-http": "^0.203.0",
"@opentelemetry/exporter-metrics-otlp-http": "^0.203.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
"@opentelemetry/instrumentation-http": "^0.203.0",
"@opentelemetry/otlp-exporter-base": "^0.203.0",
"@opentelemetry/otlp-proto-exporter-base": "^0.51.1",
"@opentelemetry/otlp-transformer": "^0.203.0",
"@opentelemetry/resources": "^2.0.1",
"@opentelemetry/sdk-logs": "^0.203.0",
"@opentelemetry/sdk-metrics": "^2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/development/metrics.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { Sandbox } from 'e2b'
import { describe, expect, it } from 'vitest'

Expand Down
2 changes: 1 addition & 1 deletion src/app/(auth)/auth/cli/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AUTH_URLS, PROTECTED_URLS } from '@/configs/urls'
import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { createClient } from '@/lib/clients/supabase/server'
import { encodedRedirect } from '@/lib/utils/auth'
import { bailOutFromPPR, generateE2BUserAccessToken } from '@/lib/utils/server'
Expand Down
2 changes: 1 addition & 1 deletion src/app/(rewrites)/[[...slug]]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sitemap from '@/app/sitemap'
import { ALLOW_SEO_INDEXING } from '@/configs/flags'
import { ROUTE_REWRITE_CONFIG } from '@/configs/rewrites'
import { BASE_URL } from '@/configs/urls'
import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import {
getRewriteForPath,
rewriteContentPagesHtml,
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AUTH_URLS, PROTECTED_URLS } from '@/configs/urls'
import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { createClient } from '@/lib/clients/supabase/server'
import { encodedRedirect } from '@/lib/utils/auth'
import { redirect } from 'next/navigation'
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/auth/confirm/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AUTH_URLS, PROTECTED_URLS } from '@/configs/urls'
import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { createClient } from '@/lib/clients/supabase/server'
import { encodedRedirect } from '@/lib/utils/auth'
import { redirect } from 'next/navigation'
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/teams/[teamId]/sandboxes/metrics/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { infra } from '@/lib/clients/api'
import { createClient } from '@/lib/clients/supabase/server'
import { transformMetricsToClientMetrics } from '@/lib/utils/sandboxes'

import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { handleDefaultInfraError } from '@/lib/utils/action'
import { MetricsRequestSchema, MetricsResponse } from './types'

Expand Down
7 changes: 4 additions & 3 deletions src/app/dashboard/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { COOKIE_KEYS } from '@/configs/keys'
import { PROTECTED_URLS } from '@/configs/urls'
import { supabaseAdmin } from '@/lib/clients/supabase/admin'
import { createClient } from '@/lib/clients/supabase/server'
import { checkAuthenticated } from '@/lib/utils/server'
import { cookies } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server'

Expand Down Expand Up @@ -30,9 +31,9 @@ export async function GET(request: NextRequest) {
// 2. Create Supabase client and get user
const supabase = await createClient()

const { data, error } = await supabase.auth.getUser()
const { user } = await checkAuthenticated()

if (error || !data.user) {
if (!user) {
// Redirect to sign-in if not authenticated
return NextResponse.redirect(new URL('/sign-in', request.url))
}
Expand All @@ -53,7 +54,7 @@ export async function GET(request: NextRequest) {
team:teams(*)
`
)
.eq('user_id', data.user.id)
.eq('user_id', user.id)

if (!teamsData?.length) {
// No teams, redirect to new team creation
Expand Down
2 changes: 1 addition & 1 deletion src/features/dashboard/sandbox/header/refresh.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { PollingButton } from '@/ui/polling-button'
import { useCallback, useState } from 'react'
import { serializeError } from 'serialize-error'
Expand Down
2 changes: 1 addition & 1 deletion src/features/dashboard/sandbox/inspect/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { PROTECTED_URLS } from '@/configs/urls'
import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { useSandboxInspectAnalytics } from '@/lib/hooks/use-analytics'
import { cn } from '@/lib/utils'
import { AsciiBackgroundPattern } from '@/ui/patterns'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { useSandboxInspectAnalytics } from '@/lib/hooks/use-analytics'
import { cn } from '@/lib/utils'
import { Button } from '@/ui/primitives/button'
Expand Down
2 changes: 1 addition & 1 deletion src/features/dashboard/sandboxes/table-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ColumnDef, FilterFn, useReactTable } from '@tanstack/react-table'
import { isWithinInterval } from 'date-fns'
import { DateRange } from 'react-day-picker'

import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { ClientSandboxMetric } from '@/types/sandboxes.types'
import posthog from 'posthog-js'
import { serializeError } from 'serialize-error'
Expand Down
2 changes: 1 addition & 1 deletion src/features/dashboard/usage/cost-card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { getUsageThroughReactCache } from '@/server/usage/get-usage'
import { ChartPlaceholder } from '@/ui/chart-placeholder'
import {
Expand Down
2 changes: 1 addition & 1 deletion src/features/dashboard/usage/ram-card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { getUsageThroughReactCache } from '@/server/usage/get-usage'
import { ChartPlaceholder } from '@/ui/chart-placeholder'
import {
Expand Down
2 changes: 1 addition & 1 deletion src/features/dashboard/usage/vcpu-card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { l } from '@/lib/clients/logger/logger'
import { l } from '@/lib/clients/logger'
import { getUsageThroughReactCache } from '@/server/usage/get-usage'
import { ChartPlaceholder } from '@/ui/chart-placeholder'
import {
Expand Down
22 changes: 1 addition & 21 deletions src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export async function register() {
if (!process.env.OTEL_EXPORTER_OTLP_ENDPOINT) return

if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./instrumentation.node')
await import('./instrumentation/instrumentation.node')
}

if (process.env.NEXT_RUNTIME === 'edge') {
Expand All @@ -16,11 +16,6 @@ export async function register() {
VERCEL_REGION,
VERCEL_DEPLOYMENT_ID,
VERCEL_GIT_COMMIT_SHA,
VERCEL_GIT_COMMIT_MESSAGE,
VERCEL_GIT_COMMIT_AUTHOR_NAME,
VERCEL_GIT_REPO_SLUG,
VERCEL_GIT_REPO_OWNER,
VERCEL_GIT_PROVIDER,
} = process.env

registerOTel({
Expand All @@ -40,21 +35,6 @@ export async function register() {
...(VERCEL_GIT_COMMIT_SHA && {
'vercel.git.commit_sha': VERCEL_GIT_COMMIT_SHA,
}),
...(VERCEL_GIT_COMMIT_MESSAGE && {
'vercel.git.commit_message': VERCEL_GIT_COMMIT_MESSAGE,
}),
...(VERCEL_GIT_COMMIT_AUTHOR_NAME && {
'vercel.git.commit_author': VERCEL_GIT_COMMIT_AUTHOR_NAME,
}),
...(VERCEL_GIT_REPO_SLUG && {
'vercel.git.repo_slug': VERCEL_GIT_REPO_SLUG,
}),
...(VERCEL_GIT_REPO_OWNER && {
'vercel.git.repo_owner': VERCEL_GIT_REPO_OWNER,
}),
...(VERCEL_GIT_PROVIDER && {
'vercel.git.provider': VERCEL_GIT_PROVIDER,
}),
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import {
hostDetector,
resourceFromAttributes,
} from '@opentelemetry/resources'
import { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs'
import { SimpleLogRecordProcessor } from '@opentelemetry/sdk-logs'
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'
import { NodeSDK } from '@opentelemetry/sdk-node'
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base'
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
} from '@opentelemetry/semantic-conventions'
import { FetchInstrumentation } from '@vercel/otel'
import { CompositeSpanProcessor } from './span-processor'
import { VercelRuntimeSpanExporter } from './vercel/exporter'

function parseResourceAttributes(
resourceAttrs?: string
Expand Down Expand Up @@ -44,20 +47,20 @@ const {
VERCEL_REGION,
VERCEL_DEPLOYMENT_ID,
VERCEL_GIT_COMMIT_SHA,
VERCEL_GIT_COMMIT_MESSAGE,
VERCEL_GIT_COMMIT_AUTHOR_NAME,
VERCEL_GIT_REPO_SLUG,
VERCEL_GIT_REPO_OWNER,
VERCEL_GIT_PROVIDER,
} = process.env

const traceExporter = new OTLPTraceExporter({
url: `${OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`,
})

const sdk = new NodeSDK({
resource: resourceFromAttributes({
[ATTR_SERVICE_NAME]: OTEL_SERVICE_NAME || 'e2b-dashboard',
[ATTR_SERVICE_VERSION]: process.env.BUILD,
// Parse additional resource attributes from environment
...parseResourceAttributes(OTEL_RESOURCE_ATTRIBUTES),
// Vercel context
'vercel.runtime': process.env.NEXT_RUNTIME || 'nodejs',
...(VERCEL_ENV && { 'vercel.env': VERCEL_ENV }),
...(VERCEL_URL && { 'vercel.url': VERCEL_URL }),
...(VERCEL_PROJECT_PRODUCTION_URL && {
Expand All @@ -71,30 +74,23 @@ const sdk = new NodeSDK({
...(VERCEL_GIT_COMMIT_SHA && {
'vercel.git.commit_sha': VERCEL_GIT_COMMIT_SHA,
}),
...(VERCEL_GIT_COMMIT_MESSAGE && {
'vercel.git.commit_message': VERCEL_GIT_COMMIT_MESSAGE,
}),
...(VERCEL_GIT_COMMIT_AUTHOR_NAME && {
'vercel.git.commit_author': VERCEL_GIT_COMMIT_AUTHOR_NAME,
}),
...(VERCEL_GIT_REPO_SLUG && {
'vercel.git.repo_slug': VERCEL_GIT_REPO_SLUG,
}),
...(VERCEL_GIT_REPO_OWNER && {
'vercel.git.repo_owner': VERCEL_GIT_REPO_OWNER,
}),
...(VERCEL_GIT_PROVIDER && { 'vercel.git.provider': VERCEL_GIT_PROVIDER }),
}),
traceExporter: new OTLPTraceExporter({
url: `${OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`,
}),
spanProcessors: [
new CompositeSpanProcessor(
[
new BatchSpanProcessor(new VercelRuntimeSpanExporter()),
new BatchSpanProcessor(traceExporter),
],
undefined
),
],
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({
url: `${OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics`,
}),
}),
logRecordProcessors: [
new BatchLogRecordProcessor(
new SimpleLogRecordProcessor(
new OTLPLogExporter({
url: `${OTEL_EXPORTER_OTLP_ENDPOINT}/v1/logs`,
})
Expand All @@ -106,6 +102,9 @@ const sdk = new NodeSDK({
'@opentelemetry/instrumentation-fs': {
enabled: false,
},
'@opentelemetry/instrumentation-http': {
enabled: false,
},
}),
new FetchInstrumentation(),
],
Expand Down
Loading
Loading