diff --git a/CHANGELOG.md b/CHANGELOG.md index c1560ab7296..c36eea69c6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1500](https://github.com/open-telemetry/opentelemetry-python/pull/1500)) ### Changed +- remove `service_name` from constructor of jaeger and opencensus exporters and + use of env variable `OTEL_PYTHON_SERVICE_NAME` + ([#1669])(https://github.com/open-telemetry/opentelemetry-python/pull/1669) - Rename `IdsGenerator` to `IdGenerator` ([#1651](https://github.com/open-telemetry/opentelemetry-python/pull/1651)) - Make TracerProvider's resource attribute private diff --git a/docs/examples/opencensus-exporter-tracer/collector.py b/docs/examples/opencensus-exporter-tracer/collector.py index fdc45d71622..5c98cc4ce9f 100644 --- a/docs/examples/opencensus-exporter-tracer/collector.py +++ b/docs/examples/opencensus-exporter-tracer/collector.py @@ -21,9 +21,7 @@ from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor -exporter = OpenCensusSpanExporter( - service_name="basic-service", endpoint="localhost:55678" -) +exporter = OpenCensusSpanExporter(endpoint="localhost:55678") trace.set_tracer_provider(TracerProvider()) tracer = trace.get_tracer(__name__) diff --git a/docs/getting_started/jaeger_example.py b/docs/getting_started/jaeger_example.py index a75f0c5d754..3d31b18fb93 100644 --- a/docs/getting_started/jaeger_example.py +++ b/docs/getting_started/jaeger_example.py @@ -15,13 +15,17 @@ # jaeger_example.py from opentelemetry import trace from opentelemetry.exporter.jaeger.thrift import JaegerExporter +from opentelemetry.sdk.resources import SERVICE_NAME, Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor -trace.set_tracer_provider(TracerProvider()) +trace.set_tracer_provider( + TracerProvider( + resource=Resource.create({SERVICE_NAME: "my-helloworld-service"}) + ) +) jaeger_exporter = JaegerExporter( - service_name="my-helloworld-service", agent_host_name="localhost", agent_port=6831, ) diff --git a/exporter/opentelemetry-exporter-jaeger-proto/examples/jaeger_exporter_example.py b/exporter/opentelemetry-exporter-jaeger-proto/examples/jaeger_exporter_example.py index 8ee0cc6bef1..a6e10fd6648 100644 --- a/exporter/opentelemetry-exporter-jaeger-proto/examples/jaeger_exporter_example.py +++ b/exporter/opentelemetry-exporter-jaeger-proto/examples/jaeger_exporter_example.py @@ -15,7 +15,6 @@ # `EXPORTER_JAEGER_CERTIFICATE` with file containing creds. jaeger_exporter = proto.JaegerExporter( - service_name="my-helloworld-service", collector_endpoint="localhost:14250", insecure=True, ) diff --git a/exporter/opentelemetry-exporter-jaeger-proto/tests/test_jaeger_exporter_protobuf.py b/exporter/opentelemetry-exporter-jaeger-proto/tests/test_jaeger_exporter_protobuf.py index 869b29fbac3..6e1778b3aa2 100644 --- a/exporter/opentelemetry-exporter-jaeger-proto/tests/test_jaeger_exporter_protobuf.py +++ b/exporter/opentelemetry-exporter-jaeger-proto/tests/test_jaeger_exporter_protobuf.py @@ -32,8 +32,9 @@ from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_JAEGER_CERTIFICATE, OTEL_EXPORTER_JAEGER_ENDPOINT, + OTEL_RESOURCE_ATTRIBUTES, ) -from opentelemetry.sdk.trace import Resource +from opentelemetry.sdk.trace import Resource, TracerProvider from opentelemetry.sdk.util.instrumentation import InstrumentationInfo from opentelemetry.trace.status import Status, StatusCode @@ -51,6 +52,7 @@ def setUp(self): self._test_span = trace._Span("test_span", context=context) self._test_span.start() self._test_span.end() + # pylint: disable=protected-access def test_constructor_by_environment_variables(self): @@ -66,18 +68,18 @@ def test_constructor_by_environment_variables(self): OTEL_EXPORTER_JAEGER_ENDPOINT: collector_endpoint, OTEL_EXPORTER_JAEGER_CERTIFICATE: os.path.dirname(__file__) + "/certs/cred.cert", + OTEL_RESOURCE_ATTRIBUTES: "service.name=my-opentelemetry-jaeger", }, ) env_patch.start() - - exporter = JaegerExporter(service_name=service,) - + provider = TracerProvider(resource=Resource.create({})) + trace_api.set_tracer_provider(provider) + exporter = JaegerExporter() self.assertEqual(exporter.service_name, service) self.assertIsNotNone(exporter._collector_grpc_client) self.assertEqual(exporter.collector_endpoint, collector_endpoint) self.assertIsNotNone(exporter.credentials) - env_patch.stop() # pylint: disable=too-many-locals,too-many-statements @@ -122,8 +124,8 @@ def test_translate_to_jaeger(self): event_timestamp = base_time + 50 * 10 ** 6 # pylint:disable=protected-access - event_timestamp_proto = pb_translator._proto_timestamp_from_epoch_nanos( - event_timestamp + event_timestamp_proto = ( + pb_translator._proto_timestamp_from_epoch_nanos(event_timestamp) ) event = trace.Event( @@ -335,7 +337,9 @@ def test_translate_to_jaeger(self): duration=span2_duration, flags=0, tags=default_tags, - process=model_pb2.Process(service_name="svc",), + process=model_pb2.Process( + service_name="svc", + ), ), model_pb2.Span( operation_name=span_names[2], @@ -366,7 +370,9 @@ def test_translate_to_jaeger(self): v_str="version", ), ], - process=model_pb2.Process(service_name="svc",), + process=model_pb2.Process( + service_name="svc", + ), ), ] @@ -374,7 +380,8 @@ def test_translate_to_jaeger(self): # (attributes) in otel is not important but in jeager it is # pylint: disable=no-member self.assertCountEqual( - spans[0].logs[0].fields, expected_spans[0].logs[0].fields, + spans[0].logs[0].fields, + expected_spans[0].logs[0].fields, ) self.assertEqual(spans, expected_spans) diff --git a/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/__init__.py b/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/__init__.py index 0df0d9db908..d32ac3144d8 100644 --- a/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/__init__.py +++ b/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/__init__.py @@ -40,7 +40,6 @@ # create a JaegerExporter jaeger_exporter = JaegerExporter( - service_name='my-helloworld-service', # configure agent agent_host_name='localhost', agent_port=6831, @@ -80,6 +79,7 @@ from os import environ from typing import Optional +from opentelemetry import trace from opentelemetry.exporter.jaeger.thrift.gen.jaeger import ( Collector as jaeger_thrift, ) @@ -96,6 +96,7 @@ OTEL_EXPORTER_JAEGER_PASSWORD, OTEL_EXPORTER_JAEGER_USER, ) +from opentelemetry.sdk.resources import SERVICE_NAME, Resource from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult DEFAULT_AGENT_HOST_NAME = "localhost" @@ -108,8 +109,6 @@ class JaegerExporter(SpanExporter): """Jaeger span exporter for OpenTelemetry. Args: - service_name: Service that logged an annotation in a trace.Classifier - when query for spans. agent_host_name: The host name of the Jaeger-Agent. agent_port: The port of the Jaeger-Agent. collector_endpoint: The endpoint of the Jaeger collector that uses @@ -124,7 +123,6 @@ class JaegerExporter(SpanExporter): def __init__( self, - service_name: str, agent_host_name: Optional[str] = None, agent_port: Optional[int] = None, collector_endpoint: Optional[str] = None, @@ -133,7 +131,6 @@ def __init__( max_tag_value_length: Optional[int] = None, udp_split_oversized_batches: bool = None, ): - self.service_name = service_name self._max_tag_value_length = max_tag_value_length self.agent_host_name = _parameter_setter( param=agent_host_name, @@ -179,6 +176,11 @@ def __init__( default=None, ) self._collector = None + self.service_name = ( + tracer_provider.resource.attributes[SERVICE_NAME] + if getattr(tracer_provider, "resource", None) + else Resource.create().attributes.get(SERVICE_NAME) + ) @property def _collector_http_client(self) -> Optional[Collector]: @@ -198,6 +200,7 @@ def _collector_http_client(self) -> Optional[Collector]: return self._collector def export(self, spans) -> SpanExportResult: + translator = Translate(spans) thrift_translator = ThriftTranslator(self._max_tag_value_length) jaeger_spans = translator._translate(thrift_translator) diff --git a/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py b/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py index 14f3d11b60a..450a6dc788f 100644 --- a/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py +++ b/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py @@ -15,6 +15,7 @@ import unittest from unittest import mock +from unittest.mock import patch # pylint:disable=no-name-in-module # pylint:disable=import-error @@ -33,7 +34,8 @@ OTEL_EXPORTER_JAEGER_PASSWORD, OTEL_EXPORTER_JAEGER_USER, ) -from opentelemetry.sdk.trace import Resource +from opentelemetry.sdk.resources import SERVICE_NAME +from opentelemetry.sdk.trace import Resource, TracerProvider from opentelemetry.sdk.util.instrumentation import InstrumentationInfo from opentelemetry.trace import SpanKind from opentelemetry.trace.status import Status, StatusCode @@ -53,14 +55,21 @@ def setUp(self): self._test_span.end() # pylint: disable=protected-access + @patch("opentelemetry.exporter.jaeger.trace._TRACER_PROVIDER", None) def test_constructor_default(self): # pylint: disable=protected-access """Test the default values assigned by constructor.""" service_name = "my-service-name" agent_host_name = "localhost" agent_port = 6831 - exporter = jaeger_exporter.JaegerExporter(service_name) + trace_api.set_tracer_provider( + TracerProvider( + resource=Resource.create({SERVICE_NAME: "my-service-name"}) + ) + ) + + exporter = jaeger_exporter.JaegerExporter() self.assertEqual(exporter.service_name, service_name) self.assertEqual(exporter.agent_host_name, agent_host_name) self.assertEqual(exporter.agent_port, agent_port) @@ -71,6 +80,7 @@ def test_constructor_default(self): self.assertTrue(exporter._agent_client is not None) self.assertIsNone(exporter._max_tag_value_length) + @patch("opentelemetry.exporter.jaeger.trace._TRACER_PROVIDER", None) def test_constructor_explicit(self): # pylint: disable=protected-access """Test the constructor passing all the options.""" @@ -83,9 +93,15 @@ def test_constructor_explicit(self): username = "username" password = "password" auth = (username, password) + trace_api.set_tracer_provider( + TracerProvider( + resource=Resource.create( + {SERVICE_NAME: "my-opentelemetry-jaeger"} + ) + ) + ) exporter = jaeger_exporter.JaegerExporter( - service_name=service, agent_host_name=agent_host_name, agent_port=agent_port, collector_endpoint=collector_endpoint, @@ -93,7 +109,6 @@ def test_constructor_explicit(self): password=password, max_tag_value_length=42, ) - self.assertEqual(exporter.service_name, service) self.assertEqual(exporter.agent_host_name, agent_host_name) self.assertEqual(exporter.agent_port, agent_port) @@ -110,6 +125,7 @@ def test_constructor_explicit(self): self.assertTrue(exporter._collector_http_client.auth is None) self.assertEqual(exporter._max_tag_value_length, 42) + @patch("opentelemetry.exporter.jaeger.trace._TRACER_PROVIDER", None) def test_constructor_by_environment_variables(self): # pylint: disable=protected-access """Test the constructor using Environment Variables.""" @@ -135,10 +151,16 @@ def test_constructor_by_environment_variables(self): }, ) - environ_patcher.start() - - exporter = jaeger_exporter.JaegerExporter(service_name=service) + trace_api.set_tracer_provider( + TracerProvider( + resource=Resource.create( + {SERVICE_NAME: "my-opentelemetry-jaeger"} + ) + ) + ) + environ_patcher.start() + exporter = jaeger_exporter.JaegerExporter() self.assertEqual(exporter.service_name, service) self.assertEqual(exporter.agent_host_name, agent_host_name) self.assertEqual(exporter.agent_port, int(agent_port)) @@ -154,9 +176,17 @@ def test_constructor_by_environment_variables(self): exporter.password = None self.assertNotEqual(exporter._collector_http_client, collector) self.assertTrue(exporter._collector_http_client.auth is None) - environ_patcher.stop() + @patch("opentelemetry.exporter.jaeger.trace._TRACER_PROVIDER", None) + def test_constructor_with_no_traceprovider_resource(self): + + """Test the constructor when there is no resource attached to trace_provider""" + + exporter = jaeger_exporter.JaegerExporter() + + self.assertEqual(exporter.service_name, "unknown_service") + def test_nsec_to_usec_round(self): # pylint: disable=protected-access nsec_to_usec_round = jaeger_exporter.translate._nsec_to_usec_round @@ -428,10 +458,19 @@ def test_translate_to_jaeger(self): self.assertEqual(spans, expected_spans) + @patch("opentelemetry.exporter.jaeger.trace._TRACER_PROVIDER", None) def test_export(self): + """Test that agent and/or collector are invoked""" + + trace_api.set_tracer_provider( + TracerProvider( + resource=Resource.create({SERVICE_NAME: "text_export"}) + ) + ) + exporter = jaeger_exporter.JaegerExporter( - "test_export", agent_host_name="localhost", agent_port=6318 + agent_host_name="localhost", agent_port=6318 ) # just agent is configured now @@ -450,6 +489,7 @@ def test_export(self): exporter.export((self._test_span,)) self.assertEqual(agent_client_mock.emit.call_count, 1) self.assertEqual(collector_mock.submit.call_count, 1) + # trace_api._TRACER_PROVIDER = None def test_agent_client(self): agent_client = jaeger_exporter.AgentClientUDP( diff --git a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py index 6a779c09fec..4bea1af1565 100644 --- a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py @@ -25,6 +25,8 @@ from opencensus.proto.trace.v1 import trace_pb2 import opentelemetry.exporter.opencensus.util as utils +from opentelemetry import trace +from opentelemetry.sdk.resources import SERVICE_NAME, Resource from opentelemetry.sdk.trace import ReadableSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult @@ -39,18 +41,19 @@ class OpenCensusSpanExporter(SpanExporter): Args: endpoint: OpenCensus Collector receiver endpoint. - service_name: Name of Collector service. host_name: Host name. client: TraceService client stub. """ def __init__( - self, - endpoint=DEFAULT_ENDPOINT, - service_name=None, - host_name=None, - client=None, + self, endpoint=DEFAULT_ENDPOINT, host_name=None, client=None, ): + tracer_provider = trace.get_tracer_provider() + service_name = ( + tracer_provider.resource.attributes[SERVICE_NAME] + if getattr(tracer_provider, "resource", None) + else Resource.create().attributes.get(SERVICE_NAME) + ) self.endpoint = endpoint if client is None: self.channel = grpc.insecure_channel(self.endpoint) diff --git a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py index 8fd2460de0e..ab8a3a2eb6e 100644 --- a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py +++ b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py @@ -26,6 +26,8 @@ translate_to_collector, ) from opentelemetry.sdk import trace +from opentelemetry.sdk.resources import SERVICE_NAME, Resource +from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import SpanExportResult from opentelemetry.trace import TraceFlags @@ -38,21 +40,23 @@ def test_constructor(self): "opentelemetry.exporter.opencensus.util.get_node", side_effect=mock_get_node, ) - service_name = "testServiceName" + trace_api.set_tracer_provider( + TracerProvider( + resource=Resource.create({SERVICE_NAME: "testServiceName"}) + ) + ) + host_name = "testHostName" client = grpc.insecure_channel("") endpoint = "testEndpoint" with patch: exporter = OpenCensusSpanExporter( - service_name=service_name, - host_name=host_name, - endpoint=endpoint, - client=client, + host_name=host_name, endpoint=endpoint, client=client, ) self.assertIs(exporter.client, client) self.assertEqual(exporter.endpoint, endpoint) - mock_get_node.assert_called_with(service_name, host_name) + mock_get_node.assert_called_with("testServiceName", host_name) def test_get_collector_span_kind(self): result = utils.get_collector_span_kind(trace_api.SpanKind.SERVER) diff --git a/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py b/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py index 299232fb77b..6077115b013 100644 --- a/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py +++ b/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py @@ -32,11 +32,6 @@ .. envvar:: OTEL_PYTHON_ID_GENERATOR """ -OTEL_PYTHON_SERVICE_NAME = "OTEL_PYTHON_SERVICE_NAME" -""" -.. envvar:: OTEL_PYTHON_SERVICE_NAME -""" - OTEL_TRACES_EXPORTER = "OTEL_TRACES_EXPORTER" """ .. envvar:: OTEL_TRACES_EXPORTER diff --git a/opentelemetry-distro/src/opentelemetry/distro/__init__.py b/opentelemetry-distro/src/opentelemetry/distro/__init__.py index 6496be16c5b..1adfe56ac75 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/__init__.py +++ b/opentelemetry-distro/src/opentelemetry/distro/__init__.py @@ -22,12 +22,11 @@ from opentelemetry import trace from opentelemetry.environment_variables import ( OTEL_PYTHON_ID_GENERATOR, - OTEL_PYTHON_SERVICE_NAME, OTEL_TRACES_EXPORTER, ) from opentelemetry.instrumentation.configurator import BaseConfigurator from opentelemetry.instrumentation.distro import BaseDistro -from opentelemetry.sdk.resources import Resource +from opentelemetry.sdk.resources import SERVICE_NAME, Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanExporter from opentelemetry.sdk.trace.id_generator import IdGenerator @@ -46,10 +45,6 @@ def _get_id_generator() -> str: return environ.get(OTEL_PYTHON_ID_GENERATOR, _DEFAULT_ID_GENERATOR) -def _get_service_name() -> str: - return environ.get(OTEL_PYTHON_SERVICE_NAME, "") - - def _get_exporter_names() -> Sequence[str]: trace_exporters = environ.get(OTEL_TRACES_EXPORTER) @@ -76,21 +71,13 @@ def _get_exporter_names() -> Sequence[str]: def _init_tracing( exporters: Sequence[SpanExporter], id_generator: IdGenerator ): - service_name = _get_service_name() - provider = TracerProvider( - resource=Resource.create({"service.name": service_name}), - id_generator=id_generator(), - ) + # if env var OTEL_RESOURCE_ATTRIBUTES is given, it will read the service_name + # from the env variable else defaults to "unknown_service" + provider = TracerProvider(id_generator=id_generator(),) trace.set_tracer_provider(provider) - for exporter_name, exporter_class in exporters.items(): + for _, exporter_class in exporters.items(): exporter_args = {} - if exporter_name not in [ - EXPORTER_OTLP, - EXPORTER_OTLP_SPAN, - ]: - exporter_args["service_name"] = service_name - provider.add_span_processor( BatchSpanProcessor(exporter_class(**exporter_args)) ) diff --git a/opentelemetry-distro/tests/test_configurator.py b/opentelemetry-distro/tests/test_configurator.py index 899e019113c..fa33744deae 100644 --- a/opentelemetry-distro/tests/test_configurator.py +++ b/opentelemetry-distro/tests/test_configurator.py @@ -17,6 +17,7 @@ from unittest import TestCase from unittest.mock import patch +from opentelemetry import trace from opentelemetry.distro import ( EXPORTER_OTLP, EXPORTER_OTLP_SPAN, @@ -27,10 +28,9 @@ ) from opentelemetry.environment_variables import ( OTEL_PYTHON_ID_GENERATOR, - OTEL_PYTHON_SERVICE_NAME, OTEL_TRACES_EXPORTER, ) -from opentelemetry.sdk.resources import Resource +from opentelemetry.sdk.resources import SERVICE_NAME, Resource from opentelemetry.sdk.trace.id_generator import IdGenerator, RandomIdGenerator @@ -38,7 +38,7 @@ class Provider: def __init__(self, resource=None, id_generator=None): self.id_generator = id_generator self.processor = None - self.resource = resource + self.resource = resource or Resource.create({}) def add_span_processor(self, processor): self.processor = processor @@ -50,8 +50,13 @@ def __init__(self, exporter): class Exporter: - def __init__(self, service_name): - self.service_name = service_name + def __init__(self): + tracer_provider = trace.get_tracer_provider() + self.service_name = ( + tracer_provider.resource.attributes[SERVICE_NAME] + if getattr(tracer_provider, "resource", None) + else Resource.create().attributes.get(SERVICE_NAME) + ) def shutdown(self): pass @@ -102,8 +107,10 @@ def tearDown(self): self.set_provider_patcher.stop() # pylint: disable=protected-access + @patch.dict( + environ, {"OTEL_RESOURCE_ATTRIBUTES": "service.name=my-test-service"} + ) def test_trace_init_default(self): - environ[OTEL_PYTHON_SERVICE_NAME] = "my-test-service" _init_tracing({"zipkin": Exporter}, RandomIdGenerator) self.assertEqual(self.set_provider_mock.call_count, 1) @@ -116,8 +123,11 @@ def test_trace_init_default(self): provider.processor.exporter.service_name, "my-test-service" ) + @patch.dict( + environ, + {"OTEL_RESOURCE_ATTRIBUTES": "service.name=my-otlp-test-service"}, + ) def test_trace_init_otlp(self): - environ[OTEL_PYTHON_SERVICE_NAME] = "my-otlp-test-service" _init_tracing({"otlp": OTLPExporter}, RandomIdGenerator) self.assertEqual(self.set_provider_mock.call_count, 1) @@ -131,7 +141,6 @@ def test_trace_init_otlp(self): provider.resource.attributes.get("service.name"), "my-otlp-test-service", ) - del environ[OTEL_PYTHON_SERVICE_NAME] @patch.dict(environ, {OTEL_PYTHON_ID_GENERATOR: "custom_id_generator"}) @patch("opentelemetry.distro.IdGenerator", new=IdGenerator) diff --git a/opentelemetry-instrumentation/README.rst b/opentelemetry-instrumentation/README.rst index 14ba530e830..7261c177f87 100644 --- a/opentelemetry-instrumentation/README.rst +++ b/opentelemetry-instrumentation/README.rst @@ -68,10 +68,6 @@ Well known trace exporter names: ``otlp`` is an alias for ``otlp_span``. -* ``--service-name`` or ``OTEL_PYTHON_SERVICE_NAME`` - -When present the value is passed on to the relevant exporter initializer as ``service_name`` argument. - * ``--id-generator`` or ``OTEL_PYTHON_ID_GENERATOR`` Used to specify which IDs Generator to use for the global Tracer Provider. By default, it diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py index b48cc936821..f08b0b144e7 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py @@ -22,7 +22,6 @@ from opentelemetry.environment_variables import ( OTEL_PYTHON_ID_GENERATOR, - OTEL_PYTHON_SERVICE_NAME, OTEL_TRACES_EXPORTER, ) @@ -83,8 +82,6 @@ def parse_args(): def load_config_from_cli_args(args): if args.trace_exporter: environ[OTEL_TRACES_EXPORTER] = args.trace_exporter - if args.service_name: - environ[OTEL_PYTHON_SERVICE_NAME] = args.service_name if args.id_generator: environ[OTEL_PYTHON_ID_GENERATOR] = args.id_generator diff --git a/opentelemetry-instrumentation/tests/test_run.py b/opentelemetry-instrumentation/tests/test_run.py index 69d4bdecf11..01bd86ed32f 100644 --- a/opentelemetry-instrumentation/tests/test_run.py +++ b/opentelemetry-instrumentation/tests/test_run.py @@ -18,10 +18,7 @@ from unittest import TestCase from unittest.mock import patch -from opentelemetry.environment_variables import ( - OTEL_PYTHON_SERVICE_NAME, - OTEL_TRACES_EXPORTER, -) +from opentelemetry.environment_variables import OTEL_TRACES_EXPORTER from opentelemetry.instrumentation import auto_instrumentation @@ -118,15 +115,3 @@ def test_exporter(self, _): # pylint: disable=no-self-use ): auto_instrumentation.run() self.assertEqual(environ.get(OTEL_TRACES_EXPORTER), "jaeger") - - @patch("opentelemetry.instrumentation.auto_instrumentation.execl") - def test_service_name(self, _): # pylint: disable=no-self-use - with patch("sys.argv", ["instrument", "2"]): - auto_instrumentation.run() - self.assertIsNone(environ.get(OTEL_PYTHON_SERVICE_NAME)) - - with patch("sys.argv", ["instrument", "-s", "my-service", "1", "2"]): - auto_instrumentation.run() - self.assertEqual( - environ.get(OTEL_PYTHON_SERVICE_NAME), "my-service" - ) diff --git a/tests/opentelemetry-docker-tests/tests/opencensus/test_opencensusexporter_functional.py b/tests/opentelemetry-docker-tests/tests/opencensus/test_opencensusexporter_functional.py index ce2f3a02b4d..a3c1ee20303 100644 --- a/tests/opentelemetry-docker-tests/tests/opencensus/test_opencensusexporter_functional.py +++ b/tests/opentelemetry-docker-tests/tests/opencensus/test_opencensusexporter_functional.py @@ -40,9 +40,7 @@ def setUp(self): trace.set_tracer_provider(TracerProvider()) self.tracer = trace.get_tracer(__name__) self.span_processor = ExportStatusSpanProcessor( - OpenCensusSpanExporter( - service_name="basic-service", endpoint="localhost:55678" - ) + OpenCensusSpanExporter(endpoint="localhost:55678") ) trace.get_tracer_provider().add_span_processor(self.span_processor)