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

Resources prototype #853

Merged
merged 30 commits into from
Jul 5, 2020
Merged

Conversation

AndrewAXue
Copy link
Contributor

@AndrewAXue AndrewAXue commented Jun 24, 2020

Adds Resource Detection for Google tools like GCE and for environment variable resource detection OTEL_RESOURCE. Follows open-telemetry/oteps#111 (Note at the time of writing this OTEP hasn't been updated after our offline discussion so there's currently some discrepancy).

Example:

import time

from opentelemetry import metrics
from opentelemetry.exporter.cloud_monitoring import (
    CloudMonitoringMetricsExporter,
)
from opentelemetry.sdk.metrics import Counter, MeterProvider
from opentelemetry import trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.tools.resource_detector import GoogleCloudResourceDetector
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
from opentelemetry.sdk.resources import Resource, get_aggregated_resources

resources = get_aggregated_resources([GoogleCloudResourceDetector()])

metrics.set_meter_provider(MeterProvider(resource=resources))
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)

Tests will be added in the next commit. Doing some manual testing with the code above, it correctly scrapes information when run on a GCE instance and sends it to Monitoring properly.

Addresses issue GoogleCloudPlatform/opentelemetry-operations-python#8

@AndrewAXue AndrewAXue marked this pull request as draft June 25, 2020 15:56
Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly superficial comments, the direction LGTM.

@AndrewAXue AndrewAXue marked this pull request as ready for review June 30, 2020 02:13
@AndrewAXue AndrewAXue changed the title [WIP] Cloud resources prototype Cloud resources prototype Jun 30, 2020
@AndrewAXue AndrewAXue changed the title Cloud resources prototype Resources prototype Jun 30, 2020
Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes since the last review LGTM, thanks for updating!

Copy link
Member

@james-bebbington james-bebbington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I do think that we should put the GCP resource detection code in a separate package to the trace/metric exporters, as users may want to use the GCP resource detector with a diff BE/exporter, but we can review that later

Copy link
Member

@aabmass aabmass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! What's the plan for actually registering the detectors the user wants?

@AndrewAXue
Copy link
Contributor Author

@aabmass for your comment, I plan on adding documentation + examples for both the new propagator and resource detector once we migrate to the new repo. Issue is here GoogleCloudPlatform/opentelemetry-operations-python#13.

@AndrewAXue
Copy link
Contributor Author

Currently, resource detection is being multi threaded. I'm not too aware of the ramifications of that (stuff like needing to add "suppress_instrumentation" to the context) and would love to get some feedback in that direction :)

@lzchen
Copy link
Contributor

lzchen commented Jul 2, 2020

Currently, resource detection is being multi threaded. I'm not too aware of the ramifications of that (stuff like needing to add "suppress_instrumentation" to the context) and would love to get some feedback in that direction :)

I'm not sure what you mean by resource detection is multi threaded. Do you mean detection can happen in parallel (as defined in the otep)?

docs/examples/basic_tracer/README.rst Outdated Show resolved Hide resolved
@lzchen lzchen merged commit ca8c097 into open-telemetry:master Jul 5, 2020
@AndrewAXue AndrewAXue deleted the cloud_resources branch July 6, 2020 16:40
codeboten pushed a commit that referenced this pull request Jul 7, 2020
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
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.

9 participants