Hi everyone, I'm trying to send log to SigNoz and ...
# general
c
Hi everyone, I'm trying to send log to SigNoz and not sure if I'm doing it wrong. Here's what I've done:
Copy code
logExporter, err := otlploggrpc.New(context.Background(),
		otlploggrpc.WithEndpoint(collectorURL),
	)
	if err != nil {
		// handle error
	}
	processor := log.NewBatchProcessor(logExporter)
	logProvider = log.NewLoggerProvider(
		log.WithResource(resources),
		log.WithProcessor(processor),
	)
	global.SetLoggerProvider(logProvider)
    slog.SetDefault(otelslog.NewLogger("app_name", otelslog.WithLoggerProvider(logProvider)))

    // somewhere in the code base
    <http://slog.Info|slog.Info>("some logs")
I'm expecting to see the logs in SigNoz dashboard but didn't see them. I saw there's official document suggesting exporting log using log file, is that the only way ? thanks for the help
n
For Go, there's no SDK that lets you send logs directly through OTLP, hence you're required to use the
filelog/app
receiver.
Instrument your Go application via using specific SDK to send logs data to Signoz - https://opentelemetry.io/docs/languages/go/instrumentation/#logs-sdk
c
Yes I was following the guide but didn't work out 😅
n
can you share your otel-config file?
c
I don't have config file, currently just setting
OTEL_EXPORTER_OTLP_ENDPOINT=localhost:4317
environment variable
n
no worries, please go through the above blog i shared and let me know if it answers on how to send logs directly through OTLP
c
Isn't that blog also suggesting using log file ?
h
@Chung-Yuan Hung I believe the gRPC exporter is still not supported by the Go log SDK, unless it has been added recently. Could you double-check that? If it's not available, you might try using the HTTP exporter instead.
c
unfortunately switched to HTTP exporter didn't work neither. @Hossain Mahmud did you have successful experience exporting log to SigNoZ ?
h
No, I haven't tried it with SigNoz. Do you see the logs if you use the stdout exporter?
y
I successfully submitted logs to our local Signoz distribution via grpc exporter, the exporter is created like this:
Copy code
logExporter, err := otlploggrpc.New(ctx, otlploggrpc.WithGRPCConn(conn))
an example grpcs connection:
Copy code
conn, _ := grpc.NewClient("1.2.3.4:4317", grpc.WithTransportCredentials(insecure.NewCredentials()))
an example of log submission:
Copy code
logRecord := &otellog.Record{}
logRecord.SetTimestamp(time.Now())
logRecord.SetSeverity(otellog.SeverityError)
logRecord.SetBody(otellog.StringValue("busy doing hard work"))
logger.Emit(ctx, *logRecord)