Skip to content

Commit 9c0ccd7

Browse files
authored
Merge pull request #246 from lzchen/res
2 parents 44bea29 + 4f1e009 commit 9c0ccd7

File tree

18 files changed

+44
-47
lines changed

18 files changed

+44
-47
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
([#243](https://github.com/microsoft/ApplicationInsights-Python/pull/243))
4343
- Move symbols to protected, add docstring for api, pin opentelemtry-api/sdk versions
4444
([#244](https://github.com/microsoft/ApplicationInsights-Python/pull/244))
45+
- Replace service.X configurations with Resource
46+
([#246](https://github.com/microsoft/ApplicationInsights-Python/pull/246))
4547

4648
## [1.0.0b8](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b8) - 2022-09-26
4749

azure-monitor-opentelemetry-distro/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,15 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to
4343

4444
* connection_string - The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in.
4545
* instrumentations - Specifies the libraries with [instrumentations][ot_instrumentations] that you would like to use. Accepts a comma separated list. e.g. `["requests", "flask"]`
46-
* service_name - Specifies the [service][service_semantic_convention_doc] name.
47-
* service_namespace - Specifies the [service][service_semantic_convention_doc] namespace.
48-
* service_instance_id - Specifies the [service][service_semantic_convention_doc] instance id.
4946
* disable_logging - If set to `True`, disables collection and export of logging telemetry. Defaults to `False`.
5047
* disable_metrics - If set to `True`, disables collection and export of metric telemetry. Defaults to `False`.
5148
* disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`.
49+
* resource - Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior.
5250
* logging_level - Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Defaults to logging.NOTSET.
5351
* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger.
5452
* logging_export_interval_millis - Specifies the logging export interval in milliseconds. Defaults to 5000.
5553
* metric_readers - Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader].
56-
* views - Specifies the list of [views][opentelemetry_specification_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage.
54+
* views - Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage.
5755
* sampling_ratio - Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out.
5856
* tracing_export_interval_millis - Specifies the distributed tracing export interval in milliseconds. Defaults to 5000.
5957

@@ -111,13 +109,14 @@ Samples are available [here][samples] to demonstrate how to utilize the above co
111109
[ot_python_docs]: https://opentelemetry.io/docs/instrumentation/python/
112110
[ot_sdk_python]: https://github.com/open-telemetry/opentelemetry-python
113111
[ot_sdk_python_metric_reader]: https://opentelemetry-python.readthedocs.io/en/stable/sdk/metrics.export.html#opentelemetry.sdk.metrics.export.MetricReader
112+
[ot_sdk_python_resource]: https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py#L153
114113
[ot_sdk_python_view_examples]: https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples/metrics/views
115114
[opentelemetry_instrumentation_requests]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-requests
116115
[opentelemetry_instrumentation_django]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-django
117116
[opentelemetry_instrumentation_flask]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-flask
118117
[opentelemetry_instrumentation_psycopg2]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-psycopg2
119-
[opentelemetry_specification_view]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#view
118+
[opentelemetry_spec_resource]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-sdk
119+
[opentelemetry_spec_view]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#view
120120
[python]: https://www.python.org/downloads/
121121
[pip]: https://pypi.org/project/pip/
122122
[samples]: https://github.com/microsoft/ApplicationInsights-Python/tree/main/azure-monitor-opentelemetry-distro/samples
123-
[service_semantic_convention_doc]: https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions#service

azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/__init__.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from opentelemetry.sdk.resources import Resource
2525
from opentelemetry.sdk.trace import TracerProvider
2626
from opentelemetry.sdk.trace.export import BatchSpanProcessor
27-
from opentelemetry.semconv.resource import ResourceAttributes
2827
from opentelemetry.trace import get_tracer_provider, set_tracer_provider
2928

3029
_logger = getLogger(__name__)
@@ -46,9 +45,7 @@ def configure_azure_monitor(**kwargs) -> None:
4645
configuration can be done via arguments passed to this function.
4746
:keyword str connection_string: Connection string for your Application Insights resource.
4847
:keyword Sequence[str] connection_string: Specifies the libraries with instrumentations to be enabled.
49-
:keyword str service_name: Specifies the service name.
50-
:keyword str service_namespace: Specifies the service namespace.
51-
:keyword str service_instance_id: Specifies the service instance id.
48+
:keyword Resource resource: Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application.
5249
:keyword bool disable_logging: If set to `True`, disables collection and export of logging telemetry. Defaults to `False`.
5350
:keyword bool disable_metrics: If set to `True`, disables collection and export of metric telemetry. Defaults to `False`.
5451
:keyword bool disable_tracing: If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`.
@@ -94,16 +91,7 @@ def configure_azure_monitor(**kwargs) -> None:
9491

9592

9693
def _get_resource(configurations: Dict[str, ConfigurationValue]) -> Resource:
97-
service_name = configurations.get("service_name", "")
98-
service_namespace = configurations.get("service_namespace", "")
99-
service_instance_id = configurations.get("service_instance_id", "")
100-
return Resource.create(
101-
{
102-
ResourceAttributes.SERVICE_NAME: service_name,
103-
ResourceAttributes.SERVICE_NAMESPACE: service_namespace,
104-
ResourceAttributes.SERVICE_INSTANCE_ID: service_instance_id,
105-
}
106-
)
94+
return configurations.get("resource", Resource.create())
10795

10896

10997
def _setup_tracing(

azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
from opentelemetry.sdk.metrics.export import MetricReader
1010
from opentelemetry.sdk.metrics.view import View
11+
from opentelemetry.sdk.resources import Resource
1112

1213
ConfigurationValue = Union[
1314
str,
1415
bool,
1516
int,
1617
float,
18+
Resource,
1719
Sequence[str],
1820
Sequence[bool],
1921
Sequence[int],

azure-monitor-opentelemetry-distro/samples/logging/correlated_logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
configure_azure_monitor(
1313
connection_string="<your-connection-string>",
14-
service_name="foo_service",
14+
logger_name=__name__,
1515
logging_level=WARNING,
1616
disable_metrics=True,
1717
disable_tracing=True,

azure-monitor-opentelemetry-distro/samples/logging/custom_properties.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
configure_azure_monitor(
1212
connection_string="<your-connection-string>",
13-
service_name="foo_service",
1413
logger_name=__name__,
1514
logging_level=DEBUG,
1615
disable_metrics=True,

azure-monitor-opentelemetry-distro/samples/logging/exception_logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
configure_azure_monitor(
1212
connection_string="<your-connection-string>",
13-
service_name="foo_service",
13+
logger_name=__name__,
1414
logging_level=WARNING,
1515
disable_metrics=True,
1616
disable_tracing=True,

azure-monitor-opentelemetry-distro/samples/logging/logs_with_traces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
configure_azure_monitor(
1313
connection_string="<your-connection-string>",
14-
service_name="flask_service_name",
14+
logger_name=__name__,
1515
logging_level=WARNING,
1616
disable_metrics=True,
1717
instrumentations=["flask"],

azure-monitor-opentelemetry-distro/samples/logging/simple.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77
from logging import WARNING, getLogger
88

99
from azure.monitor.opentelemetry.distro import configure_azure_monitor
10+
from opentelemetry.sdk.resources import Resource, ResourceAttributes
1011

1112
configure_azure_monitor(
1213
connection_string="<your-connection-string>",
13-
service_name="foo_service",
14+
logger_name=__name__,
1415
logging_level=WARNING,
16+
resource=Resource.create(
17+
{
18+
ResourceAttributes.SERVICE_NAME: "simple_service",
19+
ResourceAttributes.SERVICE_INSTANCE_ID: "simple_logging_instance",
20+
}
21+
),
1522
disable_metrics=True,
1623
disable_tracing=True,
1724
)

azure-monitor-opentelemetry-distro/samples/metrics/attributes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# Configure Azure monitor collection telemetry pipeline
77
configure_azure_monitor(
88
connection_string="<your-connection-string>",
9-
service_name="metric_attribute_service",
109
disable_logging=True,
1110
disable_tracing=True,
1211
)

0 commit comments

Comments
 (0)