mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
Merge remote-tracking branch 'upstream/main' into check-workspace-member-compiler-options
This commit is contained in:
commit
01fb217e9b
12 changed files with 1142 additions and 1053 deletions
|
@ -447,8 +447,9 @@ fn resolve_flags_and_init(
|
|||
}
|
||||
};
|
||||
|
||||
deno_telemetry::init(crate::args::otel_runtime_config())?;
|
||||
util::logger::init(flags.log_level, Some(flags.otel_config()));
|
||||
let otel_config = flags.otel_config();
|
||||
deno_telemetry::init(crate::args::otel_runtime_config(), &otel_config)?;
|
||||
util::logger::init(flags.log_level, Some(otel_config));
|
||||
|
||||
// TODO(bartlomieju): remove in Deno v2.5 and hard error then.
|
||||
if flags.unstable_config.legacy_flag_enabled {
|
||||
|
|
|
@ -89,7 +89,10 @@ fn main() {
|
|||
let future = async move {
|
||||
match standalone {
|
||||
Ok(Some(data)) => {
|
||||
deno_telemetry::init(crate::args::otel_runtime_config())?;
|
||||
deno_telemetry::init(
|
||||
crate::args::otel_runtime_config(),
|
||||
&data.metadata.otel_config,
|
||||
)?;
|
||||
util::logger::init(
|
||||
data.metadata.log_level,
|
||||
Some(data.metadata.otel_config.clone()),
|
||||
|
|
31
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
31
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
|
@ -1301,20 +1301,43 @@ declare namespace Deno {
|
|||
*/
|
||||
export namespace telemetry {
|
||||
/**
|
||||
* A SpanExporter compatible with OpenTelemetry.js
|
||||
* https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk_trace_base.SpanExporter.html
|
||||
* A TracerProvider compatible with OpenTelemetry.js
|
||||
* https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.TracerProvider.html
|
||||
*
|
||||
* This is a singleton object that implements the OpenTelemetry
|
||||
* TracerProvider interface.
|
||||
*
|
||||
* @category Telemetry
|
||||
* @experimental
|
||||
*/
|
||||
export class SpanExporter {}
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export const tracerProvider: any;
|
||||
|
||||
/**
|
||||
* A ContextManager compatible with OpenTelemetry.js
|
||||
* https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.ContextManager.html
|
||||
*
|
||||
* This is a singleton object that implements the OpenTelemetry
|
||||
* ContextManager interface.
|
||||
*
|
||||
* @category Telemetry
|
||||
* @experimental
|
||||
*/
|
||||
export class ContextManager {}
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export const contextManager: any;
|
||||
|
||||
/**
|
||||
* A MeterProvider compatible with OpenTelemetry.js
|
||||
* https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.MeterProvider.html
|
||||
*
|
||||
* This is a singleton object that implements the OpenTelemetry
|
||||
* MeterProvider interface.
|
||||
*
|
||||
* @category Telemetry
|
||||
* @experimental
|
||||
*/
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export const meterProvider: any;
|
||||
|
||||
export {}; // only export exports
|
||||
}
|
||||
|
|
|
@ -59,10 +59,9 @@ import {
|
|||
} from "ext:deno_fetch/23_response.js";
|
||||
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
|
||||
import {
|
||||
endSpan,
|
||||
builtinTracer,
|
||||
enterSpan,
|
||||
exitSpan,
|
||||
Span,
|
||||
restoreContext,
|
||||
TRACING_ENABLED,
|
||||
} from "ext:deno_telemetry/telemetry.ts";
|
||||
import {
|
||||
|
@ -320,10 +319,10 @@ function httpRedirectFetch(request, response, terminator) {
|
|||
// Drop confidential headers when redirecting to a less secure protocol
|
||||
// or to a different domain that is not a superdomain
|
||||
if (
|
||||
locationURL.protocol !== currentURL.protocol &&
|
||||
locationURL.protocol !== "https:" ||
|
||||
locationURL.host !== currentURL.host &&
|
||||
!isSubdomain(locationURL.host, currentURL.host)
|
||||
(locationURL.protocol !== currentURL.protocol &&
|
||||
locationURL.protocol !== "https:") ||
|
||||
(locationURL.host !== currentURL.host &&
|
||||
!isSubdomain(locationURL.host, currentURL.host))
|
||||
) {
|
||||
for (let i = 0; i < request.headerList.length; i++) {
|
||||
if (
|
||||
|
@ -352,10 +351,11 @@ function httpRedirectFetch(request, response, terminator) {
|
|||
*/
|
||||
function fetch(input, init = { __proto__: null }) {
|
||||
let span;
|
||||
let context;
|
||||
try {
|
||||
if (TRACING_ENABLED) {
|
||||
span = new Span("fetch", { kind: 2 });
|
||||
enterSpan(span);
|
||||
span = builtinTracer().startSpan("fetch", { kind: 2 });
|
||||
context = enterSpan(span);
|
||||
}
|
||||
|
||||
// There is an async dispatch later that causes a stack trace disconnect.
|
||||
|
@ -454,9 +454,7 @@ function fetch(input, init = { __proto__: null }) {
|
|||
await opPromise;
|
||||
return result;
|
||||
} finally {
|
||||
if (span) {
|
||||
endSpan(span);
|
||||
}
|
||||
span?.end();
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
@ -469,19 +467,17 @@ function fetch(input, init = { __proto__: null }) {
|
|||
// XXX: This should always be true, otherwise `opPromise` would be present.
|
||||
if (op_fetch_promise_is_settled(result)) {
|
||||
// It's already settled.
|
||||
endSpan(span);
|
||||
span?.end();
|
||||
} else {
|
||||
// Not settled yet, we can return a new wrapper promise.
|
||||
return SafePromisePrototypeFinally(result, () => {
|
||||
endSpan(span);
|
||||
span?.end();
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} finally {
|
||||
if (span) {
|
||||
exitSpan(span);
|
||||
}
|
||||
if (context) restoreContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -508,8 +504,11 @@ function abortFetch(request, responseObject, error) {
|
|||
*/
|
||||
function isSubdomain(subdomain, domain) {
|
||||
const dot = subdomain.length - domain.length - 1;
|
||||
return dot > 0 && subdomain[dot] === "." &&
|
||||
StringPrototypeEndsWith(subdomain, domain);
|
||||
return (
|
||||
dot > 0 &&
|
||||
subdomain[dot] === "." &&
|
||||
StringPrototypeEndsWith(subdomain, domain)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,10 +43,7 @@ const {
|
|||
Uint8Array,
|
||||
Promise,
|
||||
} = primordials;
|
||||
const {
|
||||
getAsyncContext,
|
||||
setAsyncContext,
|
||||
} = core;
|
||||
const { getAsyncContext, setAsyncContext } = core;
|
||||
|
||||
import { InnerBody } from "ext:deno_fetch/22_body.js";
|
||||
import { Event } from "ext:deno_web/02_event.js";
|
||||
|
@ -90,9 +87,8 @@ import {
|
|||
import { hasTlsKeyPairOptions, listenTls } from "ext:deno_net/02_tls.js";
|
||||
import { SymbolAsyncDispose } from "ext:deno_web/00_infra.js";
|
||||
import {
|
||||
endSpan,
|
||||
builtinTracer,
|
||||
enterSpan,
|
||||
Span,
|
||||
TRACING_ENABLED,
|
||||
} from "ext:deno_telemetry/telemetry.ts";
|
||||
import {
|
||||
|
@ -288,28 +284,28 @@ class InnerRequest {
|
|||
|
||||
// * is valid for OPTIONS
|
||||
if (path === "*") {
|
||||
return this.#urlValue = "*";
|
||||
return (this.#urlValue = "*");
|
||||
}
|
||||
|
||||
// If the path is empty, return the authority (valid for CONNECT)
|
||||
if (path == "") {
|
||||
return this.#urlValue = this.#methodAndUri[1];
|
||||
return (this.#urlValue = this.#methodAndUri[1]);
|
||||
}
|
||||
|
||||
// CONNECT requires an authority
|
||||
if (this.#methodAndUri[0] == "CONNECT") {
|
||||
return this.#urlValue = this.#methodAndUri[1];
|
||||
return (this.#urlValue = this.#methodAndUri[1]);
|
||||
}
|
||||
|
||||
const hostname = this.#methodAndUri[1];
|
||||
if (hostname) {
|
||||
// Construct a URL from the scheme, the hostname, and the path
|
||||
return this.#urlValue = this.#context.scheme + hostname + path;
|
||||
return (this.#urlValue = this.#context.scheme + hostname + path);
|
||||
}
|
||||
|
||||
// Construct a URL from the scheme, the fallback hostname, and the path
|
||||
return this.#urlValue = this.#context.scheme + this.#context.fallbackHost +
|
||||
path;
|
||||
return (this.#urlValue = this.#context.scheme + this.#context.fallbackHost +
|
||||
path);
|
||||
}
|
||||
|
||||
get completed() {
|
||||
|
@ -414,10 +410,7 @@ class InnerRequest {
|
|||
return;
|
||||
}
|
||||
|
||||
PromisePrototypeThen(
|
||||
op_http_request_on_cancel(this.#external),
|
||||
callback,
|
||||
);
|
||||
PromisePrototypeThen(op_http_request_on_cancel(this.#external), callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -521,12 +514,7 @@ function fastSyncResponseOrStream(
|
|||
autoClose = true;
|
||||
}
|
||||
PromisePrototypeThen(
|
||||
op_http_set_response_body_resource(
|
||||
req,
|
||||
rid,
|
||||
autoClose,
|
||||
status,
|
||||
),
|
||||
op_http_set_response_body_resource(req, rid, autoClose, status),
|
||||
(success) => {
|
||||
innerRequest?.close(success);
|
||||
op_http_close_after_finish(req);
|
||||
|
@ -556,10 +544,7 @@ function mapToCallback(context, callback, onError) {
|
|||
updateSpanFromRequest(span, request);
|
||||
}
|
||||
|
||||
response = await callback(
|
||||
request,
|
||||
new ServeHandlerInfo(innerRequest),
|
||||
);
|
||||
response = await callback(request, new ServeHandlerInfo(innerRequest));
|
||||
|
||||
// Throwing Error if the handler return value is not a Response class
|
||||
if (!ObjectPrototypeIsPrototypeOf(ResponsePrototype, response)) {
|
||||
|
@ -636,12 +621,12 @@ function mapToCallback(context, callback, onError) {
|
|||
mapped = function (req, _span) {
|
||||
const oldCtx = getAsyncContext();
|
||||
setAsyncContext(context.asyncContext);
|
||||
const span = new Span("deno.serve", { kind: 1 });
|
||||
const span = builtinTracer().startSpan("deno.serve", { kind: 1 });
|
||||
try {
|
||||
enterSpan(span);
|
||||
return SafePromisePrototypeFinally(
|
||||
origMapped(req, span),
|
||||
() => endSpan(span),
|
||||
() => span.end(),
|
||||
);
|
||||
} finally {
|
||||
// equiv to exitSpan.
|
||||
|
@ -688,7 +673,7 @@ function formatHostName(hostname: string): string {
|
|||
// because browsers in Windows don't resolve "0.0.0.0".
|
||||
// See the discussion in https://github.com/denoland/deno_std/issues/1165
|
||||
if (
|
||||
(Deno.build.os === "windows") &&
|
||||
Deno.build.os === "windows" &&
|
||||
(hostname == "0.0.0.0" || hostname == "::")
|
||||
) {
|
||||
return "localhost";
|
||||
|
@ -730,11 +715,12 @@ function serve(arg1, arg2) {
|
|||
const wantsHttps = hasTlsKeyPairOptions(options);
|
||||
const wantsUnix = ObjectHasOwn(options, "path");
|
||||
const signal = options.signal;
|
||||
const onError = options.onError ?? function (error) {
|
||||
// deno-lint-ignore no-console
|
||||
console.error(error);
|
||||
return internalServerError();
|
||||
};
|
||||
const onError = options.onError ??
|
||||
function (error) {
|
||||
// deno-lint-ignore no-console
|
||||
console.error(error);
|
||||
return internalServerError();
|
||||
};
|
||||
|
||||
if (wantsUnix) {
|
||||
const listener = listen({
|
||||
|
@ -843,10 +829,7 @@ function serveHttpOn(context, addr, callback) {
|
|||
const promiseErrorHandler = (error) => {
|
||||
// Abnormal exit
|
||||
// deno-lint-ignore no-console
|
||||
console.error(
|
||||
"Terminating Deno.serve loop due to unexpected error",
|
||||
error,
|
||||
);
|
||||
console.error("Terminating Deno.serve loop due to unexpected error", error);
|
||||
context.close();
|
||||
};
|
||||
|
||||
|
@ -964,7 +947,7 @@ function registerDeclarativeServer(exports) {
|
|||
port: servePort,
|
||||
hostname: serveHost,
|
||||
[kLoadBalanced]: (serveIsMain && serveWorkerCount > 1) ||
|
||||
(serveWorkerCount !== null),
|
||||
serveWorkerCount !== null,
|
||||
onListen: ({ port, hostname }) => {
|
||||
if (serveIsMain) {
|
||||
const nThreads = serveWorkerCount > 1
|
||||
|
|
1063
ext/telemetry/lib.rs
1063
ext/telemetry/lib.rs
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,38 +1,15 @@
|
|||
// Copyright 2024-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { context } from "npm:@opentelemetry/api@1";
|
||||
import {
|
||||
BasicTracerProvider,
|
||||
SimpleSpanProcessor,
|
||||
} from "npm:@opentelemetry/sdk-trace-base@1";
|
||||
import { context, trace, metrics } from "npm:@opentelemetry/api@1";
|
||||
|
||||
// @ts-ignore Deno.telemetry is not typed yet
|
||||
const telemetry = Deno.telemetry ?? Deno.tracing;
|
||||
|
||||
let COUNTER = 1;
|
||||
|
||||
/**
|
||||
* Register `Deno.telemetry` with the OpenTelemetry library.
|
||||
*/
|
||||
export function register() {
|
||||
context.setGlobalContextManager(
|
||||
new telemetry.ContextManager() ?? telemetry.ContextManager(),
|
||||
);
|
||||
|
||||
const provider = new BasicTracerProvider({
|
||||
idGenerator: Deno.env.get("DENO_UNSTABLE_OTEL_DETERMINISTIC") === "1" ? {
|
||||
generateSpanId() {
|
||||
return "1" + String(COUNTER++).padStart(15, "0");
|
||||
},
|
||||
generateTraceId() {
|
||||
return "1" + String(COUNTER++).padStart(31, "0");
|
||||
}
|
||||
} : undefined
|
||||
});
|
||||
|
||||
// @ts-ignore Deno.tracing is not typed yet
|
||||
const exporter = new telemetry.SpanExporter();
|
||||
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
|
||||
|
||||
provider.register();
|
||||
context.setGlobalContextManager(telemetry.contextManager);
|
||||
trace.setGlobalTracerProvider(telemetry.tracerProvider);
|
||||
metrics.setGlobalMeterProvider(telemetry.meterProvider);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"spans": [
|
||||
{
|
||||
"traceId": "00000000000000000000000000000001",
|
||||
"spanId": "0000000000000002",
|
||||
"spanId": "0000000000000001",
|
||||
"traceState": "",
|
||||
"parentSpanId": "",
|
||||
"flags": 1,
|
||||
|
@ -59,8 +59,8 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"traceId": "00000000000000000000000000000003",
|
||||
"spanId": "0000000000000004",
|
||||
"traceId": "00000000000000000000000000000002",
|
||||
"spanId": "0000000000000002",
|
||||
"traceState": "",
|
||||
"parentSpanId": "",
|
||||
"flags": 1,
|
||||
|
@ -117,10 +117,10 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"traceId": "00000000000000000000000000000003",
|
||||
"spanId": "1000000000000001",
|
||||
"traceId": "00000000000000000000000000000002",
|
||||
"spanId": "0000000000000003",
|
||||
"traceState": "",
|
||||
"parentSpanId": "0000000000000004",
|
||||
"parentSpanId": "0000000000000002",
|
||||
"flags": 1,
|
||||
"name": "outer span",
|
||||
"kind": 1,
|
||||
|
@ -138,10 +138,10 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"traceId": "00000000000000000000000000000003",
|
||||
"spanId": "1000000000000002",
|
||||
"traceId": "00000000000000000000000000000002",
|
||||
"spanId": "0000000000000004",
|
||||
"traceState": "",
|
||||
"parentSpanId": "1000000000000001",
|
||||
"parentSpanId": "0000000000000003",
|
||||
"flags": 1,
|
||||
"name": "inner span",
|
||||
"kind": 1,
|
||||
|
@ -171,8 +171,8 @@
|
|||
"attributes": [],
|
||||
"droppedAttributesCount": 0,
|
||||
"flags": 1,
|
||||
"traceId": "00000000000000000000000000000003",
|
||||
"spanId": "1000000000000002"
|
||||
"traceId": "00000000000000000000000000000002",
|
||||
"spanId": "0000000000000004"
|
||||
},
|
||||
{
|
||||
"timeUnixNano": "0",
|
||||
|
@ -185,8 +185,8 @@
|
|||
"attributes": [],
|
||||
"droppedAttributesCount": 0,
|
||||
"flags": 1,
|
||||
"traceId": "00000000000000000000000000000003",
|
||||
"spanId": "1000000000000002"
|
||||
"traceId": "00000000000000000000000000000002",
|
||||
"spanId": "0000000000000004"
|
||||
}
|
||||
],
|
||||
"metrics": []
|
||||
|
|
|
@ -2,9 +2,7 @@ import { assertEquals } from "@std/assert";
|
|||
|
||||
const { ContextManager } = Deno.telemetry;
|
||||
|
||||
const cm = new ContextManager();
|
||||
|
||||
const a = cm.active();
|
||||
const a = ContextManager.active();
|
||||
const b = a.setValue("b", 1);
|
||||
const c = b.setValue("c", 2);
|
||||
|
||||
|
|
|
@ -21,8 +21,13 @@ const server = Deno.serve(
|
|||
stdout: "null",
|
||||
});
|
||||
const child = command.spawn();
|
||||
child.output()
|
||||
.then(() => server.shutdown())
|
||||
child.status
|
||||
.then((status) => {
|
||||
if (status.signal) {
|
||||
throw new Error("child process failed: " + JSON.stringify(status));
|
||||
}
|
||||
return server.shutdown();
|
||||
})
|
||||
.then(() => {
|
||||
data.logs.sort((a, b) =>
|
||||
Number(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { metrics } from "npm:@opentelemetry/api@1";
|
||||
|
||||
metrics.setGlobalMeterProvider(new Deno.telemetry.MeterProvider());
|
||||
metrics.setGlobalMeterProvider(Deno.telemetry.meterProvider);
|
||||
|
||||
const meter = metrics.getMeter("m");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue