Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opentelemetry logging handler for Azure Application Insight doesn't seem to work #2116

Open
kyu-aurelian opened this issue Aug 14, 2024 · 0 comments

Comments

@kyu-aurelian
Copy link

kyu-aurelian commented Aug 14, 2024

I am trying to send logs from workers (iow, work horse running in child processes) to Azure application insight.
I see logs that are emitted from main worker are successfully sent to Azure AI, but not the ones from the workers and the job silently fails for some reason.

My best guess is that it's due to exporter (that has connection string to Azure AI) not correctly being passed down to worker processes, but I am not 100% sure.

I double checked logger level and I am generating below log from the worker:
logging.warn("Testing")

Below is my setting file:

import os
import sentry_sdk

from opentelemetry._logs import set_logger_provider
from opentelemetry.sdk._logs import (
    LoggerProvider,
    LoggingHandler,
)
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor

from azure.monitor.opentelemetry.exporter import AzureMonitorLogExporter

REDIS_HOST = os.environ.get("REDISHOST")
REDIS_PORT = int(os.environ.get("REDISPORT"))
REDIS_PASSWORD = os.environ.get("REDISPASSWORD")
REDIS_DB = 0
REDIS_SSL = True

QUEUES = ["test"]

SENTRY_DSN = << sentry url >>

sentry_sdk.init(
    dsn=SENTRY_DSN,
    enable_tracing=True,
)

logger_provider = LoggerProvider()
set_logger_provider(logger_provider)

exporter = AzureMonitorLogExporter(
    connection_string=os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)

logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter))

# # Logging configuration
DICT_CONFIG = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "default": {
            "level": "WARNING",
            "class": "opentelemetry.sdk._logs.LoggingHandler",
        },
    },
    "loggers": {
        "root": {  
            "handlers": ["default"],
            "level": "WARNING",
            "propagate": False,
        },
    },
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant