Started with Local Source Code, made sure langSmith is connected properly, but log traces not printing upon adding to langsmith_trace.py #5124

Closed
opened 2026-02-21 18:09:29 -05:00 by yindo · 1 comment
Owner

Originally created by @dchang10 on GitHub (Aug 20, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.7.0

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Start with Source code

  • start api and web
  • make sure langsmith is configured to the app
  • run Screenshot 2024-08-20 at 9 58 00 PM
  • check console

I also added several prints and logs and debugs throughout ops_trace_task.py and langsmith_trace.py. Most of the time none of the logs I've written showed up. Sometimes some pops through here and there but could never consistently replicate the situation. Example as below:
Screenshot 2024-08-20 at 9 58 41 PM

Why I think the following print should show:
I made sure the correct logs showed up in langsmith.

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @dchang10 on GitHub (Aug 20, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.7.0 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce Start with Source code - start api and web - make sure langsmith is configured to the app - run <img width="631" alt="Screenshot 2024-08-20 at 9 58 00 PM" src="https://github.com/user-attachments/assets/222c958f-323f-4c92-927a-c405e9d95d43"> - check console I also added several prints and logs and debugs throughout `ops_trace_task.py` and `langsmith_trace.py`. Most of the time none of the logs I've written showed up. Sometimes some pops through here and there but could never consistently replicate the situation. Example as below: <img width="815" alt="Screenshot 2024-08-20 at 9 58 41 PM" src="https://github.com/user-attachments/assets/6f78133d-87d0-4a1a-9a34-cec49ca50599"> Why I think the following print should show: I made sure the correct logs showed up in langsmith. ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:09:29 -05:00
yindo closed this issue 2026-02-21 18:09:29 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 20, 2024):

Hey @dchang10! I'm here to help you with your bug report and answer any questions you have. I can also assist you in becoming a contributor to the repository. Let's squash those bugs together!

The log traces are not printing consistently in langsmith_trace.py because the logging level is not set. By default, the logging level is set to WARNING, which means that DEBUG and INFO messages will not be printed. To ensure that all log messages are printed, you need to set the logging level to DEBUG or INFO.

You can set the logging level by adding the following line at the beginning of your script:

logging.basicConfig(level=logging.DEBUG)

Here is the updated code snippet with the logging level set:

import json
import logging
import os
from datetime import datetime, timedelta

from langsmith import Client

from core.ops.base_trace_instance import BaseTraceInstance
from core.ops.entities.config_entity import LangSmithConfig
from core.ops.entities.trace_entity import (
    BaseTraceInfo,
    DatasetRetrievalTraceInfo,
    GenerateNameTraceInfo,
    MessageTraceInfo,
    ModerationTraceInfo,
    SuggestedQuestionTraceInfo,
    ToolTraceInfo,
    TraceTaskName,
    WorkflowTraceInfo,
)
from core.ops.langsmith_trace.entities.langsmith_trace_entity import (
    LangSmithRunModel,
    LangSmithRunType,
    LangSmithRunUpdateModel,
)
from core.ops.utils import filter_none_values
from extensions.ext_database import db
from models.model import EndUser, MessageFile
from models.workflow import WorkflowNodeExecution

logging.basicConfig(level=logging.DEBUG)  # Set logging level to DEBUG
logger = logging.getLogger(__name__)

This will ensure that all log messages, including DEBUG and INFO, are printed to the console [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 20, 2024): <!-- Greeting --> Hey @dchang10! I'm here to help you with your bug report and answer any questions you have. I can also assist you in becoming a contributor to the repository. Let's squash those bugs together! <!-- Answer --> The log traces are not printing consistently in `langsmith_trace.py` because the logging level is not set. By default, the logging level is set to `WARNING`, which means that `DEBUG` and `INFO` messages will not be printed. To ensure that all log messages are printed, you need to set the logging level to `DEBUG` or `INFO`. You can set the logging level by adding the following line at the beginning of your script: ```python logging.basicConfig(level=logging.DEBUG) ``` Here is the updated code snippet with the logging level set: ```python import json import logging import os from datetime import datetime, timedelta from langsmith import Client from core.ops.base_trace_instance import BaseTraceInstance from core.ops.entities.config_entity import LangSmithConfig from core.ops.entities.trace_entity import ( BaseTraceInfo, DatasetRetrievalTraceInfo, GenerateNameTraceInfo, MessageTraceInfo, ModerationTraceInfo, SuggestedQuestionTraceInfo, ToolTraceInfo, TraceTaskName, WorkflowTraceInfo, ) from core.ops.langsmith_trace.entities.langsmith_trace_entity import ( LangSmithRunModel, LangSmithRunType, LangSmithRunUpdateModel, ) from core.ops.utils import filter_none_values from extensions.ext_database import db from models.model import EndUser, MessageFile from models.workflow import WorkflowNodeExecution logging.basicConfig(level=logging.DEBUG) # Set logging level to DEBUG logger = logging.getLogger(__name__) ``` This will ensure that all log messages, including `DEBUG` and `INFO`, are printed to the console <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/ops/langsmith_trace/langsmith_trace.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5124