Open bbaabemhp opened 4 days ago
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @hectorhdzg @jeremydvoss @lzchen.
@bbaabemhp
A few questions:
trace
telemetry log and take a screenshot of the attributes of the log (most notably, I want to see "sdkVersion" field.Hey @lzchen, thanks for your answer:
This is the sdkVersion:
The python script runs with "poetry run python app.py" and uvicorn is defined in the code itself. Here is an updated code to show the problem and hopefully is reproducible for you too:
# telemetry.py
import logging
from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry import trace
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry.instrumentation.logging import LoggingInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
from opentelemetry.trace import get_tracer_provider
from orchestrator.settings import settings
def configure_tracing(app=None):
if settings.APPLICATIONINSIGHTS_CONNECTION_STRING:
configure_azure_monitor(
connection_string=settings.APPLICATIONINSIGHTS_CONNECTION_STRING,
enable_live_metrics=True,
logger_name="orchestrator",
)
else:
provider = TracerProvider()
console_exporter = ConsoleSpanExporter()
provider.add_span_processor(BatchSpanProcessor(console_exporter))
trace.set_tracer_provider(provider)
RequestsInstrumentor().instrument()
LoggingInstrumentor().instrument(set_logging_format=True, log_level=logging.DEBUG)
if app:
FastAPIInstrumentor.instrument_app(app)
tracer = trace.get_tracer(__name__, tracer_provider=get_tracer_provider())
return tracer
# main.py
import uvicorn
from dotenv import load_dotenv
from fastapi import FastAPI
from logging_config import suppress_warnings
from orchestrator.settings import settings
from orchestrator.telemetry import configure_tracing
import logging
load_dotenv()
suppress_warnings()
app = FastAPI()
tracer = configure_tracing(app)
logger = logging.getLogger("orchestrator")
@app.get("/")
def health():
logger.info("Hello from root endpoint")
return {"response":"Hello"}
def start() -> None:
uvicorn.run(
"main:app",
host="0.0.0.0",
port=int(settings.ORCHESTRATOR_PORT),
reload=False,
workers=3,
)
if __name__ == "__main__":
start()
With this result:
Hey guys,
I have a simple Python app, which I connected with Azure App Insights and OpenTelemetry. But, whenever I log something with the standard
logging
library, it is getting logged twice in Azure App Insights Logs (while locally, things are getting logged only once). I use the following code:And my settings:
And this is the result in Azure App Insights Logs: