Google Cloud integrations for OpenTelemetry
Project description
This library provides support for:
Exporting traces to Google Cloud Trace
Exporting metrics to Google Cloud Monitoring
For resource detection and GCP trace context propagation, see opentelemetry-tools-google-cloud.
Installation
pip install opentelemetry-exporter-google-cloud
Usage
Traces
from opentelemetry import trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
SimpleExportSpanProcessor,
)
trace.set_tracer_provider(TracerProvider())
cloud_trace_exporter = CloudTraceSpanExporter(
project_id='my-gcloud-project',
)
trace.get_tracer_provider().add_span_processor(
SimpleExportSpanProcessor(cloud_trace_exporter)
)
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span('foo'):
print('Hello world!')
Metrics
import time
from opentelemetry import metrics
from opentelemetry.exporter.cloud_monitoring import (
CloudMonitoringMetricsExporter,
)
from opentelemetry.sdk.metrics import Counter, MeterProvider
metrics.set_meter_provider(MeterProvider())
meter = metrics.get_meter(__name__)
metrics.get_meter_provider().start_pipeline(
meter, CloudMonitoringMetricsExporter(), 5
)
requests_counter = meter.create_metric(
name="request_counter",
description="number of requests",
unit="1",
value_type=int,
metric_type=Counter,
label_keys=("environment"),
)
staging_labels = {"environment": "staging"}
for i in range(20):
requests_counter.add(25, staging_labels)
time.sleep(10)
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for opentelemetry-exporter-google-cloud-0.13b0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84bc13d400a8f6672a76941280d1d1823f15d8c3f7b67adc4234cfa95aa92ffa |
|
MD5 | 43e0c5fcfd2e07f93403ae8af1b2af34 |
|
BLAKE2b-256 | f2b187fca7dd37e5d1657b927eda9a6b664192795a930d9fe9d8200c3ca88324 |
Close
Hashes for opentelemetry_exporter_google_cloud-0.13b0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d73dc084262abd7a68d2eed7fcdcb7882aa365cef81def928ca8fc6555e63439 |
|
MD5 | bef689fb975ecb3df9ba141561b7879b |
|
BLAKE2b-256 | 4934cc96a0515e5ff60e908c26651056e040e937f7b8510b9af5a08ccd168b17 |