-
Notifications
You must be signed in to change notification settings - Fork 28
Migrate to jsr specifiers #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,73 +1,70 @@ | ||
| // Derived from https://github.com/denoland/deno_std/blob/main/log/handlers.ts | ||
| import * as log from 'https://deno.land/std@0.203.0/log/mod.ts'; | ||
| import * as log from "jsr:@std/log"; | ||
|
|
||
| import type { LogRecord } from 'https://deno.land/std@0.203.0/log/logger.ts'; | ||
| import { | ||
| LevelName, | ||
| LogLevels, | ||
| } from 'https://deno.land/std@0.203.0/log/levels.ts'; | ||
| import { LevelName, LogLevels } from "jsr:@std/log/levels"; | ||
| import type { LogRecord } from "jsr:@std/log/logger"; | ||
|
Comment on lines
+2
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
These imports replace the pinned |
||
|
|
||
| import { SeverityNumber, logs } from 'npm:@opentelemetry/api-logs@0.43.0'; | ||
| import { OTLPLogExporter } from 'npm:@opentelemetry/exporter-logs-otlp-http@0.43.0'; | ||
| import { OTLPExporterNodeConfigBase } from 'npm:@opentelemetry/otlp-exporter-base@0.43.0'; | ||
| import { logs, SeverityNumber } from "npm:@opentelemetry/api-logs@0.43.0"; | ||
| import { OTLPLogExporter } from "npm:@opentelemetry/exporter-logs-otlp-http@0.43.0"; | ||
| import { OTLPExporterNodeConfigBase } from "npm:@opentelemetry/otlp-exporter-base@0.43.0"; | ||
| import { | ||
| Resource, | ||
| detectResourcesSync, | ||
| envDetectorSync, | ||
| hostDetectorSync, | ||
| osDetectorSync, | ||
| processDetector, | ||
| } from 'npm:@opentelemetry/resources@1.17.0'; | ||
| Resource, | ||
| } from "npm:@opentelemetry/resources@1.17.0"; | ||
| import { | ||
| BatchLogRecordProcessor, | ||
| ConsoleLogRecordExporter, | ||
| BufferConfig, | ||
| ConsoleLogRecordExporter, | ||
| LoggerProvider, | ||
| } from 'npm:@opentelemetry/sdk-logs@0.43.0'; | ||
| } from "npm:@opentelemetry/sdk-logs@0.43.0"; | ||
|
|
||
| import type { Logger } from 'npm:@opentelemetry/api-logs@0.43.0'; | ||
| import type { Attributes } from 'npm:@opentelemetry/api@1.6.0'; | ||
| import type { Logger } from "npm:@opentelemetry/api-logs@0.43.0"; | ||
| import type { Attributes } from "npm:@opentelemetry/api@1.6.0"; | ||
|
|
||
| const UNSPECIFIED_SEVERITY_TEXT = ''; | ||
| const UNSPECIFIED_SEVERITY_TEXT = ""; | ||
|
|
||
| // https://github.com/open-telemetry/opentelemetry-specification/blob/fc8289b8879f3a37e1eba5b4e445c94e74b20359/specification/logs/data-model.md#displaying-severity | ||
| const OTEL_SEVERITY_NAME_MAP = { | ||
| 0: UNSPECIFIED_SEVERITY_TEXT, // XXX: This is not to spec | ||
| 1: 'TRACE', | ||
| 2: 'TRACE2', | ||
| 3: 'TRACE3', | ||
| 4: 'TRACE4', | ||
| 5: 'DEBUG', | ||
| 6: 'DEBUG2', | ||
| 7: 'DEBUG3', | ||
| 8: 'DEBUG4', | ||
| 9: 'INFO', | ||
| 10: 'INFO2', | ||
| 11: 'INFO3', | ||
| 12: 'INFO4', | ||
| 13: 'WARN', | ||
| 14: 'WARN2', | ||
| 15: 'WARN3', | ||
| 16: 'WARN4', | ||
| 17: 'ERROR', | ||
| 18: 'ERROR2', | ||
| 19: 'ERROR3', | ||
| 20: 'ERROR4', | ||
| 21: 'FATAL', | ||
| 22: 'FATAL2', | ||
| 23: 'FATAL3', | ||
| 24: 'FATAL4', | ||
| 1: "TRACE", | ||
| 2: "TRACE2", | ||
| 3: "TRACE3", | ||
| 4: "TRACE4", | ||
| 5: "DEBUG", | ||
| 6: "DEBUG2", | ||
| 7: "DEBUG3", | ||
| 8: "DEBUG4", | ||
| 9: "INFO", | ||
| 10: "INFO2", | ||
| 11: "INFO3", | ||
| 12: "INFO4", | ||
| 13: "WARN", | ||
| 14: "WARN2", | ||
| 15: "WARN3", | ||
| 16: "WARN4", | ||
| 17: "ERROR", | ||
| 18: "ERROR2", | ||
| 19: "ERROR3", | ||
| 20: "ERROR4", | ||
| 21: "FATAL", | ||
| 22: "FATAL2", | ||
| 23: "FATAL3", | ||
| 24: "FATAL4", | ||
| }; | ||
|
|
||
| interface HandlerOptions extends log.HandlerOptions { | ||
| exporterProtocol?: 'http' | 'console'; | ||
| interface HandlerOptions extends log.BaseHandlerOptions { | ||
| exporterProtocol?: "http" | "console"; | ||
| httpExporterOptions?: OTLPExporterNodeConfigBase; | ||
| processorConfig?: BufferConfig; | ||
| resourceAttributes?: Attributes; | ||
| detectResources?: boolean; | ||
| } | ||
|
|
||
| export class OpenTelemetryHandler extends log.handlers.BaseHandler { | ||
| export class OpenTelemetryHandler extends log.BaseHandler { | ||
| protected _logger: Logger | undefined; | ||
| protected _processor: BatchLogRecordProcessor | undefined; | ||
|
|
||
|
|
@@ -81,20 +78,17 @@ export class OpenTelemetryHandler extends log.handlers.BaseHandler { | |
| const detectedResource = detectResourcesSync({ | ||
| detectors: | ||
| // This will require a few extra deno permissions | ||
| options.detectResources === false | ||
| ? [] | ||
| : [ | ||
| envDetectorSync, | ||
| hostDetectorSync, | ||
| osDetectorSync, | ||
| processDetector, | ||
| ], | ||
| options.detectResources === false ? [] : [ | ||
| envDetectorSync, | ||
| hostDetectorSync, | ||
| osDetectorSync, | ||
| processDetector, | ||
| ], | ||
| }); | ||
|
|
||
| const exporter = | ||
| options.exporterProtocol === 'console' | ||
| ? new ConsoleLogRecordExporter() | ||
| : new OTLPLogExporter(options.httpExporterOptions); | ||
| const exporter = options.exporterProtocol === "console" | ||
| ? new ConsoleLogRecordExporter() | ||
| : new OTLPLogExporter(options.httpExporterOptions); | ||
|
|
||
| const processor = new BatchLogRecordProcessor( | ||
| exporter, | ||
|
|
@@ -112,12 +106,12 @@ export class OpenTelemetryHandler extends log.handlers.BaseHandler { | |
|
|
||
| logs.setGlobalLoggerProvider(loggerProvider); | ||
|
|
||
| const logger = logs.getLogger('deno-logger'); | ||
| const logger = logs.getLogger("deno-logger"); | ||
| this._logger = logger; | ||
| } | ||
|
|
||
| override setup() { | ||
| addEventListener('unload', this.#unloadCallback); | ||
| addEventListener("unload", this.#unloadCallback); | ||
| } | ||
|
|
||
| private toOtelSeverityNumber(level: number): SeverityNumber { | ||
|
|
@@ -126,7 +120,7 @@ export class OpenTelemetryHandler extends log.handlers.BaseHandler { | |
| return SeverityNumber.DEBUG; | ||
| case LogLevels.INFO: | ||
| return SeverityNumber.INFO; | ||
| case LogLevels.WARNING: | ||
| case LogLevels.WARN: | ||
| return SeverityNumber.WARN; | ||
| case LogLevels.ERROR: | ||
| return SeverityNumber.ERROR; | ||
|
|
@@ -144,8 +138,8 @@ export class OpenTelemetryHandler extends log.handlers.BaseHandler { | |
|
|
||
| this._logger?.emit({ | ||
| severityNumber: otelSeverityNumber, | ||
| severityText: | ||
| OTEL_SEVERITY_NAME_MAP[otelSeverityNumber] ?? UNSPECIFIED_SEVERITY_TEXT, | ||
| severityText: OTEL_SEVERITY_NAME_MAP[otelSeverityNumber] ?? | ||
| UNSPECIFIED_SEVERITY_TEXT, | ||
| body: logRecord.msg, | ||
| attributes: { | ||
| loggerName: logRecord.loggerName, | ||
|
|
@@ -159,6 +153,6 @@ export class OpenTelemetryHandler extends log.handlers.BaseHandler { | |
| override destroy() { | ||
| this.flush(); | ||
| this._processor?.shutdown(); | ||
| removeEventListener('unload', this.#unloadCallback); | ||
| removeEventListener("unload", this.#unloadCallback); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration changes string literals throughout this module to double quotes, while the repository guidance requires single quotes. This creates avoidable formatting churn and leaves the file inconsistent with the prescribed style.
Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!