Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Update samples
([#281](https://github.com/microsoft/ApplicationInsights-Python/pull/281))

## [1.0.0b12](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b12) - 2023-05-05

- Remove most configuration for Public Preview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry import trace

configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

logger = getLogger(__name__)
tracer = trace.get_tracer(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

logger = getLogger(__name__)
logger.setLevel(DEBUG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

logger = getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import flask
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

logger = getLogger(__name__)
logger.setLevel(INFO)
Expand Down
4 changes: 1 addition & 3 deletions azure-monitor-opentelemetry/samples/logging/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry.sdk.resources import Resource, ResourceAttributes

configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

logger = getLogger(__name__)

Expand Down
4 changes: 1 addition & 3 deletions azure-monitor-opentelemetry/samples/metrics/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from opentelemetry import metrics

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

attribute_set1 = {"key1": "val1"}
attribute_set2 = {"key2": "val2"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from opentelemetry.sdk.resources import Resource, ResourceAttributes

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()


# Callback functions for observable instruments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from azure.monitor.opentelemetry import configure_azure_monitor

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

# Database calls using the psycopg2 library will be automatically captured
cnx = psycopg2.connect(database="test", user="<user>", password="<password>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from django.http import HttpResponse

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()


# Requests sent to the django application will be automatically captured
Expand Down
5 changes: 2 additions & 3 deletions azure-monitor-opentelemetry/samples/tracing/http_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from azure.monitor.opentelemetry import configure_azure_monitor

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

app = fastapi.FastAPI()

Expand All @@ -26,6 +24,7 @@ async def exception():
raise Exception("Hit an exception")


# Set the OTEL_PYTHON_EXCLUDE_URLS environment variable to "http://127.0.0.1:8000/exclude"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add this env var to the README

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could. It's part of the instrumentation's readmes, but we did include it in the docs. There are other instrumentation related env vars I have not delt with much, so I think it would make sense to leave that for another PR where I add a whole section for instrumentation configuration env vars

# Telemetry from this endpoint will not be captured due to excluded_urls config above
@app.get("/exclude")
async def exclude():
Expand Down
4 changes: 1 addition & 3 deletions azure-monitor-opentelemetry/samples/tracing/http_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from azure.monitor.opentelemetry import configure_azure_monitor

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

app = flask.Flask(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
logger = logging.getLogger(__name__)

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("Request parent span") as span:
try:
# Requests made using the requests library will be automatically captured
response = requests.get("https://azure.microsoft.com/", timeout=5)
# Set the OTEL_PYTHON_EXCLUDE_URLS environment variable to "http://example.com"
# This request will not be tracked due to the excluded_urls configuration
response = requests.get("http://example.com", timeout=5)
logger.warning("Request sent")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
logger = logging.getLogger(__name__)

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("Request parent span") as span:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
logger = logging.getLogger(__name__)

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

http = urllib3.PoolManager()

Expand Down
4 changes: 1 addition & 3 deletions azure-monitor-opentelemetry/samples/tracing/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
from sqlalchemy import create_engine, text

configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

engine = create_engine("sqlite:///:memory:")
# SQLAlchemy instrumentation is not officially supported by this package
Expand Down
4 changes: 1 addition & 3 deletions azure-monitor-opentelemetry/samples/tracing/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# Sampling ratio of between 0 and 1 inclusive
# 0.1 means approximately 10% of your traces are sent

configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

tracer = trace.get_tracer(__name__)

Expand Down
4 changes: 1 addition & 3 deletions azure-monitor-opentelemetry/samples/tracing/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource, ResourceAttributes

configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

tracer = trace.get_tracer(__name__)

Expand Down