Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/opentelemetry/exporter/otlp/proto/http/__init__.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:35 +0000

1# Copyright The OpenTelemetry Authors 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15 

16""" 

17This library allows to export tracing data to an OTLP collector. 

18 

19Usage 

20----- 

21 

22The **OTLP Span Exporter** allows to export `OpenTelemetry`_ traces to the 

23`OTLP`_ collector. 

24 

25You can configure the exporter with the following environment variables: 

26 

27- :envvar:`OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` 

28- :envvar:`OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` 

29- :envvar:`OTEL_EXPORTER_OTLP_TRACES_HEADERS` 

30- :envvar:`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` 

31- :envvar:`OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` 

32- :envvar:`OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE` 

33- :envvar:`OTEL_EXPORTER_OTLP_TIMEOUT` 

34- :envvar:`OTEL_EXPORTER_OTLP_PROTOCOL` 

35- :envvar:`OTEL_EXPORTER_OTLP_HEADERS` 

36- :envvar:`OTEL_EXPORTER_OTLP_ENDPOINT` 

37- :envvar:`OTEL_EXPORTER_OTLP_COMPRESSION` 

38- :envvar:`OTEL_EXPORTER_OTLP_CERTIFICATE` 

39 

40.. _OTLP: https://github.com/open-telemetry/opentelemetry-collector/ 

41.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/ 

42 

43.. code:: python 

44 

45 from opentelemetry import trace 

46 from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter 

47 from opentelemetry.sdk.resources import Resource 

48 from opentelemetry.sdk.trace import TracerProvider 

49 from opentelemetry.sdk.trace.export import BatchSpanProcessor 

50 

51 # Resource can be required for some backends, e.g. Jaeger 

52 # If resource wouldn't be set - traces wouldn't appears in Jaeger 

53 resource = Resource(attributes={ 

54 "service.name": "service" 

55 }) 

56 

57 trace.set_tracer_provider(TracerProvider(resource=resource)) 

58 tracer = trace.get_tracer(__name__) 

59 

60 otlp_exporter = OTLPSpanExporter() 

61 

62 span_processor = BatchSpanProcessor(otlp_exporter) 

63 

64 trace.get_tracer_provider().add_span_processor(span_processor) 

65 

66 with tracer.start_as_current_span("foo"): 

67 print("Hello world!") 

68 

69API 

70--- 

71""" 

72import enum 

73 

74from .version import __version__ 

75 

76 

77_OTLP_HTTP_HEADERS = { 

78 "Content-Type": "application/x-protobuf", 

79 "User-Agent": "OTel OTLP Exporter Python/" + __version__, 

80} 

81 

82 

83class Compression(enum.Enum): 

84 NoCompression = "none" 

85 Deflate = "deflate" 

86 Gzip = "gzip"