admin管理员组文章数量:1278979
I am trying to understand how to use and send logs using opentelemetry but find it is confusing. Suppose I am developing an application(preferable using javascript) and want to log things in the app and send the logs to a backend(e.g. azure monitor), what is the best way to do it? For traces and metrics, opentelemetry provides api/sdk to either direct exports traces/metrics to backend or through collector. However, my understanding of how logs work are so different. It looks to me opentelemetry does provide some api/sdk, but I am not sure if I should use it as an application developer. I see in the opentelemetry logging overview, it mentioned two things below:
OpenTelemetry defines an API for emitting LogRecords. Application developers are NOT encouraged to call this API directly. It is provided for library authors to build Appenders, which use the API to bridge between existing logging libraries and the OpenTelemetry log data model. Existing logging libraries generally provide a much richer set of features than what is defined in OpenTelemetry. It is NOT a goal of OpenTelemetry to ship a feature-rich logging library.
OpenTelemetry defines an API for emitting Events. The API consists of convenience methods which delegate to the API for emitting LogRecords. Application developers are encouraged to call this API directly.
How do I know if this api/sdk in javascript should be used by application developer or library authors to build Appenders? It seems this api/sdk has both emit event and emit LogRecords.
I understand opentelemetry log architecture aim to make sure both logs that we do not have control and controllable logs(like in terms of formats) to have correlation and context information, so one approach(called Via File or Stdout Logs) is to save the logs to some intermediary medium and then send to collector(My understanding this is more of the case of uncontrollable logs). The second approach(called Direct to Collector) is to send logs direct to collector. In the doc of the second way, it mentions "The most convenient way to achieve this is to provide addons or extensions to the monly used logging libraries.", what does it mean? Does the addons or extensions refers to the Appenders mentioned above? I would appreciate some code examples of these two approaches in javascript especially the 2nd approach.
I am trying to understand how to use and send logs using opentelemetry but find it is confusing. Suppose I am developing an application(preferable using javascript) and want to log things in the app and send the logs to a backend(e.g. azure monitor), what is the best way to do it? For traces and metrics, opentelemetry provides api/sdk to either direct exports traces/metrics to backend or through collector. However, my understanding of how logs work are so different. It looks to me opentelemetry does provide some api/sdk, but I am not sure if I should use it as an application developer. I see in the opentelemetry logging overview, it mentioned two things below:
OpenTelemetry defines an API for emitting LogRecords. Application developers are NOT encouraged to call this API directly. It is provided for library authors to build Appenders, which use the API to bridge between existing logging libraries and the OpenTelemetry log data model. Existing logging libraries generally provide a much richer set of features than what is defined in OpenTelemetry. It is NOT a goal of OpenTelemetry to ship a feature-rich logging library.
OpenTelemetry defines an API for emitting Events. The API consists of convenience methods which delegate to the API for emitting LogRecords. Application developers are encouraged to call this API directly.
How do I know if this api/sdk in javascript should be used by application developer or library authors to build Appenders? It seems this api/sdk has both emit event and emit LogRecords.
I understand opentelemetry log architecture aim to make sure both logs that we do not have control and controllable logs(like in terms of formats) to have correlation and context information, so one approach(called Via File or Stdout Logs) is to save the logs to some intermediary medium and then send to collector(My understanding this is more of the case of uncontrollable logs). The second approach(called Direct to Collector) is to send logs direct to collector. In the doc of the second way, it mentions "The most convenient way to achieve this is to provide addons or extensions to the monly used logging libraries.", what does it mean? Does the addons or extensions refers to the Appenders mentioned above? I would appreciate some code examples of these two approaches in javascript especially the 2nd approach.
Share Improve this question asked Dec 29, 2022 at 1:11 bunnybunny 2,0378 gold badges37 silver badges66 bronze badges1 Answer
Reset to default 9Direct OTEL Log emitting via http. Maybe BatchProcessor has better performance.
Typescript:
import * as logsAPI from '@opentelemetry/api-logs';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import {
LoggerProvider,
SimpleLogRecordProcessor
} from '@opentelemetry/sdk-logs';
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
const resource = new Resource({
[ SemanticResourceAttributes.SERVICE_NAME ]: 'test',
[ SemanticResourceAttributes.SERVICE_NAMESPACE ]: 'ns_test',
});
const loggerProvider = new LoggerProvider({
resource
});
loggerProvider.addLogRecordProcessor(new SimpleLogRecordProcessor(new OTLPLogExporter({
url: 'http://otel_collector:4318',
keepAlive: true,
})));
const loggerOtel = loggerProvider.getLogger('default');
loggerOtel.emit({
severityNumber: logsAPI.SeverityNumber.INFO,
severityText: 'INFO',
body: 'test',
attributes: { 'log.type': 'LogRecord' },
});
Based on the example shown here.
本文标签: nodejsHow to use opentelemetry logs in javascript(nodejs)Stack Overflow
版权声明:本文标题:node.js - How to use opentelemetry logs in javascript(nodejs) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741291276a2370560.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论