FastAPI App Logs Not Showing in SigNoz Dashboard

TLDR Muhammed reported logs from their FastAPI app not appearing on SigNoz dashboard despite being in a Kubernetes environment. nitya-signoz suggested checking filters and namespaces, but the issue persists.

Photo of Muhammed
Muhammed
Wed, 01 Mar 2023 15:01:06 UTC

Hi, I made my fastapi app to log data into json format also I added `span_id` and `trace_id` in my log (type is `int`) but logs are not shown in signoz here is my code ```import json_logging import logging import sys from config import config from fastapi import FastAPI app = FastAPI(title=config.app_title) class JSONLogWebFormatter(json_logging.JSONLogFormatter): """ Formatter for web application log """ def _format_log_object(self, record, request_util): json_log_object = super(JSONLogWebFormatter, self)._format_log_object( record, request_util ) current_span = trace.get_current_span() if current_span: json_log_object["span_id"] = current_span.get_span_context().span_id json_log_object["trace_id"] = current_span.get_span_context().trace_id json_log_object.update( { "correlation_id": request_util.get_correlation_id( within_formatter=True ), } ) return json_log_object json_logging.init_fastapi(enable_json=True, custom_formatter=JSONLogWebFormatter) json_logging.init_request_instrument(app, custom_formatter=JSONLogWebFormatter) # init the logger as usual logger = logging.getLogger() logger.setLevel(logging._nameToLevel[config.log_level.upper()]) logger.addHandler(logging.StreamHandler(sys.stdout))```

Photo of nitya-signoz
nitya-signoz
Wed, 01 Mar 2023 15:03:55 UTC

You will have to use the SDK

Photo of nitya-signoz
nitya-signoz
Wed, 01 Mar 2023 15:04:42 UTC

Or If your application is running in docker or k8s, then logs emitted to stdout will be collected by signoz

Photo of Muhammed
Muhammed
Wed, 01 Mar 2023 15:05:24 UTC

I'm in k8s and other logs are collecting except this app

Photo of Muhammed
Muhammed
Wed, 01 Mar 2023 15:06:51 UTC

I think something are wrong with my log structure

Photo of Muhammed
Muhammed
Wed, 01 Mar 2023 15:08:19 UTC

Or with my configuration

Photo of Muhammed
Muhammed
Wed, 01 Mar 2023 15:12:20 UTC

nitya-signoz What can I do to fix that?

Photo of nitya-signoz
nitya-signoz
Wed, 01 Mar 2023 15:14:10 UTC

If you logs are getting printed to stdout then it will be collected, did you try to filter in the UI

Photo of Muhammed
Muhammed
Wed, 01 Mar 2023 15:14:28 UTC

yes

Photo of Muhammed
Muhammed
Wed, 01 Mar 2023 15:15:13 UTC

nothing shows in the SigNoz dashboard after filtering

Photo of Muhammed
Muhammed
Wed, 01 Mar 2023 15:56:12 UTC

```{ "written_at": "2023-03-01T15:56:00.206Z", "written_ts": 1677686160206573000, "msg": "", "type": "log", "logger": "fastapi-request-logger", "thread": "MainThread", "level": "INFO", "module": "implementation", "line_no": 35, "span_id": "176794658234006051", "trace_id": "227587342002673840811008499138396058579", "correlation_id": "272ba70209901ac67929a2595244ce13" }```

Photo of Muhammed
Muhammed
Wed, 01 Mar 2023 15:56:20 UTC

here is the sample log

Photo of Muhammed
Muhammed
Wed, 01 Mar 2023 16:11:40 UTC

nitya-signoz

Photo of Muhammed
Muhammed
Sat, 04 Mar 2023 14:56:22 UTC

I have removed trace_id and span_id from logs but I'm not able to see logs in signoz

Photo of Muhammed
Muhammed
Sat, 04 Mar 2023 14:57:32 UTC

nitya-signoz

Photo of nitya-signoz
nitya-signoz
Sun, 05 Mar 2023 15:42:29 UTC

Can you check if by any change if the namespace where you have deployed the above application is excluded in the otel collector config file receiver ?

Photo of Muhammed
Muhammed
Sun, 05 Mar 2023 20:55:52 UTC

``` - type: filter id: remove_some_logs expr: 'resource["k8s.namespace.name"] matches "(^stage-.*$)" and resource["k8s.namespace.name"] != "stage-this-project"' drop_ratio: 1.0```

Photo of Muhammed
Muhammed
Sun, 05 Mar 2023 20:56:08 UTC

stage-this-project is the name of the namespace

Photo of Muhammed
Muhammed
Sun, 05 Mar 2023 20:56:38 UTC

I think this filter is not making problems

Photo of nitya-signoz
nitya-signoz
Mon, 06 Mar 2023 05:18:55 UTC

It shouldn’t cause any issue, but try removing it?

Photo of nitya-signoz
nitya-signoz
Mon, 06 Mar 2023 05:19:05 UTC

or if there is something else.

Photo of Muhammed
Muhammed
Mon, 06 Mar 2023 05:22:03 UTC

I will check But there are no other drop filters If I remove that my storage will become 100% full

Photo of nitya-signoz
nitya-signoz
Mon, 06 Mar 2023 05:22:25 UTC

Got it then try deploying in some other namesapce ?

Photo of Muhammed
Muhammed
Mon, 06 Mar 2023 06:58:25 UTC

I will test that

Photo of Muhammed
Muhammed
Mon, 06 Mar 2023 07:27:03 UTC

I changed the namespace but problem persist

Photo of Muhammed
Muhammed
Tue, 07 Mar 2023 10:56:04 UTC

nitya-signoz