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

Duplicate log record on setting basic config #36318

Closed
king-11 opened this issue Jul 2, 2024 · 12 comments
Closed

Duplicate log record on setting basic config #36318

king-11 opened this issue Jul 2, 2024 · 12 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor Monitor, Monitor Ingestion, Monitor Query needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@king-11
Copy link

king-11 commented Jul 2, 2024

  • Package Name: azure-monitor-opentelemetry
  • Package Version: ^1.6.0
  • Operating System: Mariner
  • Python Version: 3.9.7

Describe the bug
I am seeing duplicate logs in AKS for the python application after enabling formatting on the logger that I create for each module. There are two logs for each logging call in the AKS container logs one with default format and one with customized format that I defined.

To Reproduce
Create logger using below code:

configure_azure_monitor(
      enable_live_metrics = True,
      disable_offline_storage = True
  )

def get_logger(name: str, level = logging.INFO):
    logger = logging.getLogger(name)
    logger.setLevel(level)
    logging.basicConfig(
        format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    )
    return logger

logger = get_logger(__name__)

logger.info("hello suspicious duplicate")

The other approach I tried was modifying get_logger as below:

console_handler = logging.StreamHandler(sys.stdout)
console_formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s : %(message)s")
console_handler.setFormatter(console_formatter)
logger.addHandler(console_handler)

This also results in duplicate logs

Expected behavior
Only my custom log should get printed

@king-11 king-11 changed the title Setting logging format Duplicate log record on setting basic config Jul 2, 2024
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jul 2, 2024
@xiangyan99 xiangyan99 added Monitor Monitor, Monitor Ingestion, Monitor Query Service Attention Workflow: This issue is responsible by Azure service team. and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Jul 2, 2024
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Jul 2, 2024
Copy link

github-actions bot commented Jul 2, 2024

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @gracewilcox @gulopesd @Haiying-MSFT @jairmyree @joshfree @KarishmaGhiya @KevinBlasko @kurtzeborn @nisha-bhatia @pvaneck @sarangan12 @scottaddie @srnagar @ToddKingMSFT.

@lzchen
Copy link
Member

lzchen commented Jul 2, 2024

@king-11

Please pass in the name of the Python logger you would like to track telemetry for like in this example. Keep in mind that every logger that is in the same namespace as the name passed in will also be tracked.

i.e., if I use logger_name="azure.app", the loggers with example names azure.app.test, azure.app.webapp and azure.app.function will be tracked but azure.testing will not.

@king-11
Copy link
Author

king-11 commented Jul 2, 2024

@lzchen passing in the logger_name="anomaly_detection" which is the parent package name also results in duplicate logging. I was just wondering if there is any way to format the log using opentelemetry distro as I think two stream handler are being created here on using the format options I have tried.

@king-11
Copy link
Author

king-11 commented Aug 2, 2024

adding more details which I recently found the two log records being generated differ in details apart from the message

sdkVersion customDimensions operation_Id client_Browser cloud_RoleName
ulm_py3.9.19:otel1.25.0:ext1.0.0b27 {"code.filepath":"/usr/lib/python3.9/site-packages/anomaly_detection/handlers/inference_handler.py","code.function":"execute_inference","code.lineno":"105"} ecd6e2a7c786da27c0e3097b37d8c6df Other impact-service
py3.9.19:oc0.11.4:ext1.1.13 {"process":"MainProcess","module":"inference_handler","fileName":"/usr/lib/python3.9/site-packages/anomaly_detection/handlers/inference_handler.py","lineNumber":"105","level":"INFO"} 00000000000000000000000000000000 Python Requests 2.32 main.py

cloud role name is incorrect for the later sdk which is the duplicate record being generated

@lzchen
Copy link
Member

lzchen commented Aug 2, 2024

@king-11

The second sdk is for the opencensus python sdk which will be deprecated in September.

@king-11
Copy link
Author

king-11 commented Aug 2, 2024

@lzchen so it comes along with azure monitor distro is it? Because I remember removing it when migrating to open telemetry.

@lzchen
Copy link
Member

lzchen commented Aug 5, 2024

@king-11

It does not come with the distro. Opencensus should be completely separate from Open Telemetry. Please make sure you are not using the old opencensus sdk and that you are not querying old data from before your testing. Also please try out your app outside of an AKS environment to see if the issue persists.

@xiangyan99 xiangyan99 added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Aug 8, 2024
@github-actions github-actions bot removed the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Aug 8, 2024
Copy link

github-actions bot commented Aug 8, 2024

Hi @king-11. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

Copy link

Hi @king-11, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

@github-actions github-actions bot added the no-recent-activity There has been no recent activity on this issue. label Aug 15, 2024
@king-11
Copy link
Author

king-11 commented Aug 20, 2024

@lzchen so I confirmed that opencensus dependency was still present in our setup.py but it isn't being imported or used anywhere. So is it possible that just the presence of this particular package in system environment causes dual export of logs?

@github-actions github-actions bot added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. labels Aug 20, 2024
@lzchen
Copy link
Member

lzchen commented Aug 20, 2024

@king-11

opencensus packing existing but not being used in your code should not cause export of logs from the opencensus azure monitor sdk. Please make sure that you are not using it anywhere in your code. I would also uninstall the package as it is deprecated.

@king-11
Copy link
Author

king-11 commented Aug 22, 2024

Closing this issue thanks for help @izchen one of our dependencies was pulling in opencensus and using it for creating an exporter.

@king-11 king-11 closed this as completed Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor Monitor, Monitor Ingestion, Monitor Query needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

4 participants