samplES
This commit is contained in:
Родитель
95cf300cb1
Коммит
d49268f783
|
@ -8,7 +8,7 @@ This distro automatically installs the following libraries:
|
|||
|
||||
## Officially supported instrumentations
|
||||
|
||||
The following OpenTelemetry instrumentations come bundled in with the Azure monitor distro. If you would like to add support for another OpenTelemetry instrumentation, please submit a feature [request][distro_feature_request]. In the meantime, you can use the OpenTelemetry instrumentation manually via it's own APIs (i.e. `instrument()`) in your code.
|
||||
The following OpenTelemetry instrumentations come bundled in with the Azure monitor distro. If you would like to add support for another OpenTelemetry instrumentation, please submit a feature [request][distro_feature_request]. In the meantime, you can use the OpenTelemetry instrumentation manually via it's own APIs (i.e. `instrument()`) in your code. See [this][samples_manual] for an example.
|
||||
|
||||
* [OpenTelemetry Django Instrumentation][opentelemetry_instrumentation_django]
|
||||
* [OpenTelemetry FastApi Instrumentation][opentelemetry_instrumentation_fastapi]
|
||||
|
@ -131,3 +131,4 @@ Samples are available [here][samples] to demonstrate how to utilize the above co
|
|||
[python]: https://www.python.org/downloads/
|
||||
[pip]: https://pypi.org/project/pip/
|
||||
[samples]: https://github.com/microsoft/ApplicationInsights-Python/tree/main/azure-monitor-opentelemetry/samples
|
||||
[samples_manual]: https://github.com/microsoft/ApplicationInsights-Python/tree/main/azure-monitor-opentelemetry/samples/tracing/manual.py
|
||||
|
|
|
@ -14,6 +14,7 @@ configure_azure_monitor(
|
|||
tracing_export_interval_millis=15000,
|
||||
)
|
||||
|
||||
# Database calls using the psycopg2 library will be automatically captured
|
||||
cnx = psycopg2.connect(database="test", user="<user>", password="<password>")
|
||||
cursor = cnx.cursor()
|
||||
cursor.execute("INSERT INTO test_tables (test_field) VALUES (123)")
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
# -------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License in the project root for
|
||||
# license information.
|
||||
# --------------------------------------------------------------------------
|
||||
from sqlalchemy import create_engine, text
|
||||
|
||||
from azure.monitor.opentelemetry import configure_azure_monitor
|
||||
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
|
||||
|
||||
configure_azure_monitor(
|
||||
connection_string="<your-connection-string>",
|
||||
tracing_export_interval_millis=15000,
|
||||
disable_logging=True,
|
||||
disable_metrics=True,
|
||||
)
|
||||
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
# SQLAlchemy instrumentation is not officially supported by this package
|
||||
# However, you can use the OpenTelemetry instument method manually in
|
||||
# conjunction with configure_azure_monitor
|
||||
SQLAlchemyInstrumentor().instrument(
|
||||
engine=engine,
|
||||
)
|
||||
|
||||
# Database calls using the SqlAlchemy library will be automatically captured
|
||||
with engine.connect() as conn:
|
||||
result = conn.execute(text("select 'hello world'"))
|
||||
print(result.all())
|
||||
|
||||
input()
|
|
@ -0,0 +1,27 @@
|
|||
# -------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See License in the project root for
|
||||
# license information.
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
from azure.monitor.opentelemetry import configure_azure_monitor
|
||||
from opentelemetry import trace
|
||||
|
||||
configure_azure_monitor(
|
||||
connection_string="<your-connection-string>",
|
||||
# Sampling ratio of between 0 and 1 inclusive
|
||||
# 0.1 means approximately 10% of your traces are sent
|
||||
sampling_ratio=0.1,
|
||||
tracing_export_interval_millis=15000,
|
||||
disable_logging=True,
|
||||
disable_metrics=True,
|
||||
)
|
||||
|
||||
tracer = trace.get_tracer(__name__)
|
||||
|
||||
for i in range(100):
|
||||
# Approximately 90% of these spans should be sampled out
|
||||
with tracer.start_as_current_span("hello"):
|
||||
print("Hello, World!")
|
||||
|
||||
input()
|
Загрузка…
Ссылка в новой задаче