Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Added

- Set `SeverityText` field to logrus hook in `go.opentelemetry.io/contrib/bridges/otellogrus`. (#7553)
- Add the unit `ns` to deprecated runtime metrics `process.runtime.go.gc.pause_total_ns` and `process.runtime.go.gc.pause_ns` in `go.opentelemetry.io/contrib/instrumentation/runtime`. (#7490)
- Add the `WithLoggerProviderOptions`, `WithMeterProviderOptions` and `WithTracerProviderOptions` options to `NewSDK` to allow passing custom options to providers in `go.opentelemetry.io/contrib/otelconf`. (#7552)

Expand Down
4 changes: 2 additions & 2 deletions bridges/otellogrus/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
//
// - Time is set as the Timestamp.
// - Message is set as the Body using a [log.StringValue].
// - Level is transformed and set as the Severity. The SeverityText is not
// set.
// - Level is transformed and set as the Severity. The SeverityText is also set.
// - Fields are transformed and set as the attributes.
//
// The Level is transformed to the OpenTelemetry
Expand Down Expand Up @@ -178,6 +177,7 @@ func (h *Hook) convertEntry(e *logrus.Entry) log.Record {
record.SetTimestamp(e.Time)
record.SetBody(log.StringValue(e.Message))
record.SetSeverity(convertSeverity(e.Level))
record.SetSeverityText(e.Level.String())
record.AddAttributes(convertFields(e.Data)...)

return record
Expand Down
61 changes: 50 additions & 11 deletions bridges/otellogrus/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ func TestHookFire(t *testing.T) {

want: logtest.Recording{
logtest.Scope{Name: name}: {
{Severity: log.SeverityFatal4, Body: log.StringValue("")},
{
Severity: log.SeverityFatal4,
SeverityText: "panic",
Body: log.StringValue(""),
},
},
},
},
Expand All @@ -178,7 +182,12 @@ func TestHookFire(t *testing.T) {
},
want: logtest.Recording{
logtest.Scope{Name: name}: {
{Severity: log.SeverityFatal4, Body: log.StringValue(""), Timestamp: now},
{
Severity: log.SeverityFatal4,
SeverityText: "panic",
Body: log.StringValue(""),
Timestamp: now,
},
},
},
},
Expand All @@ -189,7 +198,11 @@ func TestHookFire(t *testing.T) {
},
want: logtest.Recording{
logtest.Scope{Name: name}: {
{Severity: log.SeverityFatal4, Body: log.StringValue("")},
{
Severity: log.SeverityFatal4,
SeverityText: "panic",
Body: log.StringValue(""),
},
},
},
},
Expand All @@ -200,7 +213,11 @@ func TestHookFire(t *testing.T) {
},
want: logtest.Recording{
logtest.Scope{Name: name}: {
{Severity: log.SeverityFatal, Body: log.StringValue("")},
{
Severity: log.SeverityFatal,
SeverityText: "fatal",
Body: log.StringValue(""),
},
},
},
},
Expand All @@ -211,7 +228,11 @@ func TestHookFire(t *testing.T) {
},
want: logtest.Recording{
logtest.Scope{Name: name}: {
{Severity: log.SeverityError, Body: log.StringValue("")},
{
Severity: log.SeverityError,
SeverityText: "error",
Body: log.StringValue(""),
},
},
},
},
Expand All @@ -222,7 +243,11 @@ func TestHookFire(t *testing.T) {
},
want: logtest.Recording{
logtest.Scope{Name: name}: {
{Severity: log.SeverityWarn, Body: log.StringValue("")},
{
Severity: log.SeverityWarn,
SeverityText: "warning",
Body: log.StringValue(""),
},
},
},
},
Expand All @@ -233,7 +258,11 @@ func TestHookFire(t *testing.T) {
},
want: logtest.Recording{
logtest.Scope{Name: name}: {
{Severity: log.SeverityInfo, Body: log.StringValue("")},
{
Severity: log.SeverityInfo,
SeverityText: "info",
Body: log.StringValue(""),
},
},
},
},
Expand All @@ -244,7 +273,11 @@ func TestHookFire(t *testing.T) {
},
want: logtest.Recording{
logtest.Scope{Name: name}: {
{Severity: log.SeverityDebug, Body: log.StringValue("")},
{
Severity: log.SeverityDebug,
SeverityText: "debug",
Body: log.StringValue(""),
},
},
},
},
Expand All @@ -255,7 +288,11 @@ func TestHookFire(t *testing.T) {
},
want: logtest.Recording{
logtest.Scope{Name: name}: {
{Severity: log.SeverityTrace, Body: log.StringValue("")},
{
Severity: log.SeverityTrace,
SeverityText: "trace",
Body: log.StringValue(""),
},
},
},
},
Expand All @@ -269,7 +306,8 @@ func TestHookFire(t *testing.T) {
want: logtest.Recording{
logtest.Scope{Name: name}: {
{
Severity: log.SeverityFatal4,
Severity: log.SeverityFatal4,
SeverityText: "panic",
Attributes: []log.KeyValue{
log.String("hello", "world"),
},
Expand All @@ -288,7 +326,8 @@ func TestHookFire(t *testing.T) {
want: logtest.Recording{
logtest.Scope{Name: name}: {
{
Severity: log.SeverityFatal4,
Severity: log.SeverityFatal4,
SeverityText: "panic",
Attributes: []log.KeyValue{
log.Empty("nil_pointer"),
},
Expand Down
Loading