-
Notifications
You must be signed in to change notification settings - Fork 810
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
1 parent
0ab3d8d
commit 6a52c29
Showing
20 changed files
with
751 additions
and
119 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
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
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
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
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
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
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,53 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type * as logsAPI from '@opentelemetry/api-logs/experimental'; | ||
import { Logger as BaseLogger } from './Logger'; | ||
import type { InstrumentationScope } from '@opentelemetry/core'; | ||
import { context } from '@opentelemetry/api'; | ||
import { LoggerProviderSharedState } from './internal/LoggerProviderSharedState'; | ||
import { SeverityNumber } from '@opentelemetry/api-logs/experimental'; | ||
|
||
export class Logger extends BaseLogger implements logsAPI.Logger { | ||
constructor( | ||
instrumentationScope: InstrumentationScope, | ||
_sharedState: LoggerProviderSharedState | ||
) { | ||
super(instrumentationScope, _sharedState); | ||
} | ||
|
||
public emitEvent(eventRecord: logsAPI.EventRecord): void { | ||
const attributes = eventRecord.attributes || {}; | ||
|
||
// TODO: change to ATTR_EVENT_NAME, it is under experimental_attributes currently. | ||
// this will add more dependencies. | ||
attributes['event.name'] = eventRecord.name; | ||
|
||
const logRecord: logsAPI.LogRecord = { | ||
attributes: attributes, | ||
context: eventRecord.context || context.active(), | ||
severityNumber: eventRecord.severityNumber || SeverityNumber.INFO, | ||
timestamp: eventRecord.timestamp || Date.now(), | ||
}; | ||
|
||
if (eventRecord.data) { | ||
logRecord.body = eventRecord.data; | ||
} | ||
if (this.emit) { | ||
this.emit(logRecord); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
experimental/packages/sdk-logs/src/Experimental_LoggerProvider.ts
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,64 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { diag } from '@opentelemetry/api'; | ||
import type * as logsAPI from '@opentelemetry/api-logs/experimental'; | ||
import { NOOP_LOGGER } from '@opentelemetry/api-logs/experimental'; | ||
import { LoggerProvider as BaseLoggerProvider } from './LoggerProvider'; | ||
|
||
import type { LoggerProviderConfig } from './types'; | ||
import { Logger } from './Experimental_Logger'; | ||
|
||
export const DEFAULT_LOGGER_NAME = 'unknown'; | ||
|
||
export class LoggerProvider | ||
extends BaseLoggerProvider | ||
implements logsAPI.LoggerProvider | ||
{ | ||
constructor(config: LoggerProviderConfig = {}) { | ||
super(config); | ||
} | ||
|
||
/** | ||
* Get a logger with the configuration of the LoggerProvider. | ||
*/ | ||
override getLogger( | ||
name: string, | ||
version?: string, | ||
options?: logsAPI.LoggerOptions | ||
): logsAPI.Logger { | ||
if (this._shutdownOnce.isCalled) { | ||
diag.warn('A shutdown LoggerProvider cannot provide a Logger'); | ||
return NOOP_LOGGER; | ||
} | ||
|
||
if (!name) { | ||
diag.warn('Logger requested without instrumentation scope name.'); | ||
} | ||
const loggerName = name || DEFAULT_LOGGER_NAME; | ||
const key = `${loggerName}@${version || ''}:${options?.schemaUrl || ''}`; | ||
if (!this._sharedState.loggers.has(key)) { | ||
this._sharedState.loggers.set( | ||
key, | ||
new Logger( | ||
{ name: loggerName, version, schemaUrl: options?.schemaUrl }, | ||
this._sharedState | ||
) | ||
); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return this._sharedState.loggers.get(key)! as logsAPI.Logger; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export { | ||
LoggerProviderConfig, | ||
LogRecordLimits, | ||
BufferConfig, | ||
BatchLogRecordProcessorBrowserConfig, | ||
} from './types'; | ||
export { LoggerProvider } from './Experimental_LoggerProvider'; | ||
export { LogRecord } from './LogRecord'; | ||
export { LogRecordProcessor } from './LogRecordProcessor'; | ||
export { ReadableLogRecord } from './export/ReadableLogRecord'; | ||
export { NoopLogRecordProcessor } from './export/NoopLogRecordProcessor'; | ||
export { ConsoleLogRecordExporter } from './export/ConsoleLogRecordExporter'; | ||
export { LogRecordExporter } from './export/LogRecordExporter'; | ||
export { SimpleLogRecordProcessor } from './export/SimpleLogRecordProcessor'; | ||
export { InMemoryLogRecordExporter } from './export/InMemoryLogRecordExporter'; | ||
export { BatchLogRecordProcessor } from './platform'; |
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
Oops, something went wrong.