-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
451 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# files generated by next.js | ||
tsconfig.json | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export async function GET() { | ||
return new Response(JSON.stringify({ test: 'data' })) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Layout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// We are fetching our own API | ||
export const dynamic = 'force-dynamic' | ||
|
||
export default async function Page() { | ||
const data = await fetch('https://user:pass@vercel.com') | ||
return <pre>{await data.text()}</pre> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { SpanKind } from '@opentelemetry/api' | ||
|
||
export const traceFile = 'otel-trace.txt' | ||
|
||
export type SavedSpan = { | ||
traceId: string | ||
parentId?: string | ||
traceState: any | ||
name: string | ||
id: string | ||
kind: SpanKind | ||
timestamp: number | ||
duration: number | ||
attributes: Record<string, any> | ||
status: any | ||
events: any[] | ||
links: any[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Resource } from '@opentelemetry/resources' | ||
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' | ||
import { | ||
NodeTracerProvider, | ||
SimpleSpanProcessor, | ||
SpanExporter, | ||
ReadableSpan, | ||
} from '@opentelemetry/sdk-trace-node' | ||
import { | ||
ExportResult, | ||
ExportResultCode, | ||
hrTimeToMicroseconds, | ||
} from '@opentelemetry/core' | ||
import fs from 'fs-extra' | ||
|
||
import { SavedSpan, traceFile } from './constants' | ||
import path from 'path' | ||
import url from 'url' | ||
|
||
const serializeSpan = (span: ReadableSpan): SavedSpan => ({ | ||
traceId: span.spanContext().traceId, | ||
parentId: span.parentSpanId, | ||
traceState: span.spanContext().traceState?.serialize(), | ||
name: span.name, | ||
id: span.spanContext().spanId, | ||
kind: span.kind, | ||
timestamp: hrTimeToMicroseconds(span.startTime), | ||
duration: hrTimeToMicroseconds(span.duration), | ||
attributes: span.attributes, | ||
status: span.status, | ||
events: span.events, | ||
links: span.links, | ||
}) | ||
|
||
const __dirname = path.dirname(url.fileURLToPath(import.meta.url)) | ||
|
||
class TestExporter implements SpanExporter { | ||
async export( | ||
spans: ReadableSpan[], | ||
resultCallback: (result: ExportResult) => void | ||
) { | ||
const traceFullPath = path.join(__dirname, traceFile) | ||
for (const span of spans) { | ||
await fs.appendFile( | ||
traceFullPath, | ||
JSON.stringify(serializeSpan(span)) + '\n' | ||
) | ||
} | ||
resultCallback({ code: ExportResultCode.SUCCESS }) | ||
} | ||
shutdown(): Promise<void> { | ||
return Promise.resolve() | ||
} | ||
} | ||
|
||
export const register = () => { | ||
const provider = new NodeTracerProvider({ | ||
resource: new Resource({ | ||
[SemanticResourceAttributes.SERVICE_NAME]: 'test-next-app', | ||
}), | ||
}) | ||
|
||
provider.addSpanProcessor(new SimpleSpanProcessor(new TestExporter())) | ||
|
||
// Make sure to register you provider | ||
provider.register() | ||
|
||
// Creating this file will let our tests know that initialization is done | ||
fs.createFileSync('./' + traceFile) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Resource } from '@opentelemetry/resources' | ||
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' | ||
import { | ||
NodeTracerProvider, | ||
SimpleSpanProcessor, | ||
} from '@opentelemetry/sdk-trace-node' | ||
|
||
// You can use gRPC exporter instead | ||
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http' | ||
|
||
export function register() { | ||
// Next.js expects you to use to register TraceProvider. It won't work if you use NodeSDK. | ||
// We use registered provider to create traces inside of Next.js internals. | ||
const provider = new NodeTracerProvider({ | ||
resource: new Resource({ | ||
[SemanticResourceAttributes.SERVICE_NAME]: 'next-app', | ||
}), | ||
}) | ||
|
||
provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter({}))) | ||
|
||
// Make sure to register you provider | ||
provider.register() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function register() { | ||
if (process.env.NEXT_RUNTIME === 'nodejs') { | ||
if (process.env.__NEXT_TEST_MODE) { | ||
require('./instrumentation-node-test').register() | ||
} else { | ||
// We use this instrumentation for easier debugging with this test. | ||
// We want this test to be executable with `pnpm next-with-deps`. | ||
require('./instrumentation-node').register() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
experimental: { | ||
instrumentationHook: true, | ||
appDir: true, | ||
}, | ||
} |
Oops, something went wrong.