Skip to content
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

feat: add metrics_exporter for metrics_sdk #1

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

xuan-cao-swi
Copy link
Owner

@xuan-cao-swi xuan-cao-swi commented Nov 16, 2023

Description

Added otlp metrics exporter that works with otlp collector through http protocol.

Most code copied from (trace) exporter (with test as well) with the assumption of same ssl, http etc. configuration. The major change is the proto decode. If the log exporter also use the similar configuration, having a utility file can help DRY.

Quick demo

require 'opentelemetry/sdk'
require 'opentelemetry-metrics-sdk' # need to install this from building the metrics_sdk and metrics_api folder
require 'opentelemetry/exporter/otlp'

OpenTelemetry::SDK.configure

otlp_metric_exporter = OpenTelemetry::Exporter::OTLP::MetricsExporter.new

OpenTelemetry.meter_provider.add_metric_reader(otlp_metric_exporter)

meter = OpenTelemetry.meter_provider.meter("SAMPLE_METER_NAME")

histogram = meter.create_histogram('histogram', unit: 'smidgen', description: 'desscription')

histogram.record(123, attributes: {'foo' => 'bar'})

OpenTelemetry.meter_provider.metric_readers.each(&:pull)
OpenTelemetry.meter_provider.shutdown

Testing failed but it will success once the open-telemetry#1532 is merged.

@xuan-cao-swi xuan-cao-swi marked this pull request as draft November 16, 2023 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant