Skip to content

Breaking changes 0.13b0 #73

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

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ workflows:
name: tests-python3.<< matrix.python3_minor >>
matrix:
parameters:
python3_minor: [4, 5, 6, 7, 8]
python3_minor: [5, 6, 7, 8]
4 changes: 2 additions & 2 deletions dev-constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Sphinx==3.1.2
# development before GA. After GA, we will build against specific releases.
# Bump the commit frequently during development whenever you are missing
# changes from upstream.
opentelemetry-api==0.12b0
opentelemetry-sdk==0.12b0
-e git+https://github.com/open-telemetry/opentelemetry-python.git@1abdc02a92cd996f3924e1653896bb72123ac84e#egg=opentelemetry-api&subdirectory=opentelemetry-api
-e git+https://github.com/open-telemetry/opentelemetry-python.git@1abdc02a92cd996f3924e1653896bb72123ac84e#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk
1 change: 0 additions & 1 deletion docs/examples/cloud_monitoring/basic_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
unit="1",
value_type=int,
metric_type=Counter,
label_keys=("environment"),
)

staging_labels = {"environment": "staging"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
unit="1",
value_type=int,
metric_type=Counter,
label_keys=("environment"),
)

staging_labels = {"environment": "staging"}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/tools/cloud_trace_propagator/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import requests
from opentelemetry import trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.propagators import set_global_httptextformat
from opentelemetry.propagators import set_global_textmap
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
from opentelemetry.tools.cloud_trace_propagator import (
Expand All @@ -34,7 +34,7 @@
)

# Using the X-Cloud-Trace-Context header
set_global_httptextformat(CloudTraceFormatPropagator())
set_global_textmap(CloudTraceFormatPropagator())

tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("client_span"):
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/tools/cloud_trace_propagator/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from opentelemetry import trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.ext.flask import FlaskInstrumentor
from opentelemetry.propagators import set_global_httptextformat
from opentelemetry.propagators import set_global_textmap
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
from opentelemetry.tools.cloud_trace_propagator import (
Expand All @@ -40,7 +40,7 @@
)

# Using the X-Cloud-Trace-Context header
set_global_httptextformat(CloudTraceFormatPropagator())
set_global_textmap(CloudTraceFormatPropagator())


@app.route("/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ def _get_monitored_resource(
Args:
series: ProtoBuf TimeSeries
"""
resource_labels = resource.labels
if resource_labels.get("cloud.provider") != "gcp":
resource_attributes = resource.attributes
if resource_attributes.get("cloud.provider") != "gcp":
return None
resource_type = resource_labels["gcp.resource_type"]
resource_type = resource_attributes["gcp.resource_type"]
if resource_type not in OT_RESOURCE_LABEL_TO_GCP:
return None
return MonitoredResource(
type=resource_type,
labels={
gcp_label: str(resource_labels[ot_label])
gcp_label: str(resource_attributes[ot_label])
for ot_label, gcp_label in OT_RESOURCE_LABEL_TO_GCP[
resource_type
].items()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _translate_to_cloud_trace(
)

# Span does not support a MonitoredResource object. We put the
# information into labels instead.
# information into attributes instead.
resources_and_attrs = _extract_resources(span.resource)
resources_and_attrs.update(span.attributes)

Expand Down Expand Up @@ -318,7 +318,7 @@ def _strip_characters(ot_version):
return "".join(filter(lambda x: x.isdigit() or x == ".", ot_version))


OT_RESOURCE_LABEL_TO_GCP = {
OT_RESOURCE_ATTRIBUTE_TO_GCP = {
"gce_instance": {
"host.id": "instance_id",
"cloud.account.id": "project_id",
Expand All @@ -337,17 +337,17 @@ def _strip_characters(ot_version):


def _extract_resources(resource: Resource) -> Dict[str, str]:
resource_labels = resource.labels
if resource_labels.get("cloud.provider") != "gcp":
resource_attributes = resource.attributes
if resource_attributes.get("cloud.provider") != "gcp":
return {}
resource_type = resource_labels["gcp.resource_type"]
if resource_type not in OT_RESOURCE_LABEL_TO_GCP:
resource_type = resource_attributes["gcp.resource_type"]
if resource_type not in OT_RESOURCE_ATTRIBUTE_TO_GCP:
return {}
return {
"g.co/r/{}/{}".format(resource_type, gcp_resource_key,): str(
resource_labels[ot_resource_key]
resource_attributes[ot_resource_key]
)
for ot_resource_key, gcp_resource_key in OT_RESOURCE_LABEL_TO_GCP[
for ot_resource_key, gcp_resource_key in OT_RESOURCE_ATTRIBUTE_TO_GCP[
resource_type
].items()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def test_export(self):
)

resource = Resource(
labels={
attributes={
"cloud.account.id": 123,
"host.id": "host",
"cloud.zone": "US",
Expand Down Expand Up @@ -611,7 +611,7 @@ def test_extract_resources(self):
exporter._get_monitored_resource(Resource.create_empty())
)
resource = Resource(
labels={
attributes={
"cloud.account.id": 123,
"host.id": "host",
"cloud.zone": "US",
Expand All @@ -630,7 +630,7 @@ def test_extract_resources(self):
)

resource = Resource(
labels={
attributes={
"cloud.account.id": "123",
"host.id": "host",
"extra_info": "extra",
Expand All @@ -643,7 +643,7 @@ def test_extract_resources(self):
self.assertRaises(KeyError, exporter._get_monitored_resource, resource)

resource = Resource(
labels={
attributes={
"cloud.account.id": "123",
"host.id": "host",
"extra_info": "extra",
Expand All @@ -655,7 +655,7 @@ def test_extract_resources(self):
self.assertIsNone(exporter._get_monitored_resource(resource))

resource = Resource(
labels={
attributes={
"cloud.account.id": "123",
"host.id": "host",
"extra_info": "extra",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def test_extract_empty_resources(self):

def test_extract_well_formed_resources(self):
resource = Resource(
labels={
attributes={
"cloud.account.id": 123,
"host.id": "host",
"cloud.zone": "US",
Expand All @@ -582,7 +582,7 @@ def test_extract_malformed_resources(self):
# This resource doesn't have all the fields required for a gce_instance
# Specifically its missing "host.id", "cloud.zone", "cloud.account.id"
resource = Resource(
labels={
attributes={
"gcp.resource_type": "gce_instance",
"cloud.provider": "gcp",
}
Expand All @@ -593,7 +593,7 @@ def test_extract_malformed_resources(self):
def test_extract_unsupported_gcp_resources(self):
# Unsupported gcp resources will be ignored
resource = Resource(
labels={
attributes={
"cloud.account.id": "123",
"host.id": "host",
"extra_info": "extra",
Expand All @@ -607,7 +607,7 @@ def test_extract_unsupported_gcp_resources(self):
def test_extract_unsupported_provider_resources(self):
# Resources with currently unsupported providers will be ignored
resource = Resource(
labels={
attributes={
"cloud.account.id": "123",
"host.id": "host",
"extra_info": "extra",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import opentelemetry.trace as trace
from opentelemetry.context.context import Context
from opentelemetry.trace.propagation import httptextformat
from opentelemetry.trace.propagation import textmap
from opentelemetry.trace.span import (
SpanContext,
TraceFlags,
Expand All @@ -30,18 +30,16 @@
_TRACE_CONTEXT_HEADER_RE = re.compile(_TRACE_CONTEXT_HEADER_FORMAT)


class CloudTraceFormatPropagator(httptextformat.HTTPTextFormat):
class CloudTraceFormatPropagator(textmap.TextMapPropagator):
"""This class is for injecting into a carrier the SpanContext in Google
Cloud format, or extracting the SpanContext from a carrier using Google
Cloud format.
"""

def extract(
self,
get_from_carrier: httptextformat.Getter[
httptextformat.HTTPTextFormatT
],
carrier: httptextformat.HTTPTextFormatT,
get_from_carrier: textmap.Getter[textmap.TextMapPropagatorT],
carrier: textmap.TextMapPropagatorT,
context: typing.Optional[Context] = None,
) -> Context:
header = get_from_carrier(carrier, _TRACE_CONTEXT_HEADER_NAME)
Expand Down Expand Up @@ -72,8 +70,8 @@ def extract(

def inject(
self,
set_in_carrier: httptextformat.Setter[httptextformat.HTTPTextFormatT],
carrier: httptextformat.HTTPTextFormatT,
set_in_carrier: textmap.Setter[textmap.TextMapPropagatorT],
carrier: textmap.TextMapPropagatorT,
context: typing.Optional[Context] = None,
) -> None:
span = trace.get_current_span(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def test_finding_gce_resources(self, getter):
self.assertEqual(
found_resources,
Resource(
labels={
attributes={
"host.id": "instance_id",
"cloud.provider": "gcp",
"cloud.account.id": "project_id",
Expand All @@ -204,7 +204,7 @@ def test_finding_gce_resources(self, getter):
self.assertEqual(
found_resources,
Resource(
labels={
attributes={
"host.id": "instance_id",
"cloud.provider": "gcp",
"cloud.account.id": "project_id",
Expand All @@ -229,7 +229,7 @@ def test_finding_gke_resources(self, getter):
self.assertEqual(
found_resources,
Resource(
labels={
attributes={
"cloud.account.id": "project_id",
"k8s.cluster.name": "cluster_name",
"k8s.namespace.name": "namespace",
Expand Down Expand Up @@ -257,7 +257,7 @@ def test_resource_finding_fallback(self, getter):
self.assertEqual(
found_resources,
Resource(
labels={
attributes={
"host.id": "instance_id",
"cloud.provider": "gcp",
"cloud.account.id": "project_id",
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ skipsdist = True
skip_missing_interpreters = True
envlist =
; Add the `ci` factor to any env that should be running during CI.
py3{4,5,6,7,8}-ci-test-{exporter,tools}-google-cloud
py3{5,6,7,8}-ci-test-{exporter,tools}-google-cloud

; These are development commands and use the same virtualenv.
dev
Expand Down