Skip to content

Commit

Permalink
Merge branch 'main' into codeboten/env-var-parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
codeboten authored Oct 11, 2024
2 parents ae2bf71 + 79bb705 commit e08dc29
Show file tree
Hide file tree
Showing 94 changed files with 2,798 additions and 3,129 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ jobs:
test-compatibility:
runs-on: ubuntu-latest
needs: [compatibility-test]
if: always()
steps:
- name: Test if compatibility-test workflow passed
run: |
echo ${{ needs.compatibility-test.result }}
test ${{ needs.compatibility-test.result }} == "success"
3 changes: 2 additions & 1 deletion .github/workflows/links-fail-fast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
fail: true
args: --max-concurrency 5 --cache --max-cache-age 1d .
# TODO: Remove 429s exception once https://github.com/open-telemetry/opentelemetry-go-contrib/issues/6183 is resolved
args: --max-concurrency 5 --cache --max-cache-age 1d --accept 100..=103,200..=299,429 .
3 changes: 2 additions & 1 deletion .github/workflows/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: --max-concurrency 1 --cache --max-cache-age 1d .
# TODO: Remove 429s exception once https://github.com/open-telemetry/opentelemetry-go-contrib/issues/6183 is resolved
args: --max-concurrency 1 --cache --max-cache-age 1d --accept 100..=103,200..=299,429 .

- name: Create Issue From File
if: steps.lychee.outputs.exit_code != 0
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,32 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Move examples from `go.opentelemetry.io/otel` to this repository under `examples` directory. (#6158)
- Support yaml/json struct tags for generated code in `go.opentelemetry.io/contrib/config`. (#5433)
- Add support for parsing YAML configuration via `ParseYAML` in `go.opentelemetry.io/contrib/config`. (#5433)
- Add support for temporality preference configuration in `go.opentelemetry.io/contrib/config`. (#5860)
- Parsing via ParseYAML in `go.opentelemetry.io/contrib/config` now support environment variables in the format `${VAR_NAME}`. (#6215)

### Changed

- The function signature of `NewLogProcessor` in `go.opentelemetry.io/contrib/processors/minsev` has changed to accept the added `Severitier` interface instead of a `log.Severity`. (#6116)
- `NewSDK` in `go.opentelemetry.io/contrib/config` now returns a no-op SDK if `disabled` is set to `true`. (#6185)
- The deprecated `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho` package has found a Code Owner.
The package is no longer deprecated. (#6207)

### Fixed

- Possible nil dereference panic in `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace`. (#5965)
- `logrus.Level` transformed to appropriate `log.Severity` in `go.opentelemetry.io/contrib/bridges/otellogrus`. (#6191)

### Removed

- The `Minimum` field of the `LogProcessor` in `go.opentelemetry.io/contrib/processors/minsev` is removed.
Use `NewLogProcessor` to configure this setting. (#6116)
- The deprecated `go.opentelemetry.io/contrib/instrumentation/gopkg.in/macaron.v1/otelmacaron` package is removed. (#6186)
- The deprecated `go.opentelemetry.io/contrib/samplers/aws/xray` package is removed. (#6187)

### Changed

- Updated `go.opentelemetry.io/contrib/config` to use the [v0.3.0](https://github.com/open-telemetry/opentelemetry-configuration/releases/tag/v0.3.0) release of schema which includes backwards incompatible changes. (#6126)

<!-- Released section -->
<!-- Don't change this section unless doing release -->

Expand Down
3 changes: 1 addition & 2 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/ @open-te
instrumentation/github.com/emicklei/go-restful/otelrestful/ @open-telemetry/go-approvers @dashpole
instrumentation/github.com/gin-gonic/gin/otelgin/ @open-telemetry/go-approvers
instrumentation/github.com/gorilla/mux/otelmux/ @open-telemetry/go-approvers @akats7
instrumentation/github.com/labstack/echo/otelecho/ @open-telemetry/go-approvers
instrumentation/github.com/labstack/echo/otelecho/ @open-telemetry/go-approvers @scorpionknifes
instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/ @open-telemetry/go-approvers
instrumentation/google.golang.org/grpc/otelgrpc/ @open-telemetry/go-approvers @dashpole
instrumentation/gopkg.in/macaron.v1/otelmacaron/ @open-telemetry/go-approvers

instrumentation/host/ @open-telemetry/go-approvers @dmathieu
instrumentation/net/http/httptrace/otelhttptrace/ @open-telemetry/go-approvers @dmathieu
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ update-all-otel-deps:
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR=tmp/opentelememetry-configuration

# The SHA matching the current version of the opentelemetry-configuration schema to use
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_VERSION=v0.2.0
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_VERSION=v0.3.0

# Cleanup temporary directory
genjsonschema-cleanup:
Expand All @@ -326,6 +326,7 @@ genjsonschema: genjsonschema-cleanup $(GOJSONSCHEMA)
--capitalization OTLP \
--struct-name-from-title \
--package config \
--only-models \
--output ${GENERATED_CONFIG} \
${OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR}/schema/opentelemetry_configuration.json
@echo Modify jsonschema generated files.
Expand Down
38 changes: 31 additions & 7 deletions bridges/otellogrus/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
// set.
// - Fields are transformed and set as the attributes.
//
// The Level is transformed by using the static offset to the OpenTelemetry
// The Level is transformed to the OpenTelemetry
// Severity types. For example:
//
// - [logrus.DebugLevel] is transformed to [log.SeverityDebug]
// - [logrus.InfoLevel] is transformed to [log.SeverityTrace4]
// - [logrus.WarnLevel] is transformed to [log.SeverityTrace3]
// - [logrus.ErrorLevel] is transformed to [log.SeverityTrace2]
// - [logrus.InfoLevel] is transformed to [log.SeverityInfo]
// - [logrus.WarnLevel] is transformed to [log.SeverityWarn]
// - [logrus.ErrorLevel] is transformed to [log.SeverityError]
// - [logrus.FatalLevel] is transformed to [log.SeverityFatal]
// - [logrus.PanicLevel] is transformed to [log.SeverityFatal4]
//
// Field values are transformed based on their type into log attributes, or
// into a string value if there is no matching type.
Expand Down Expand Up @@ -164,9 +166,7 @@ func (h *Hook) convertEntry(e *logrus.Entry) log.Record {
var record log.Record
record.SetTimestamp(e.Time)
record.SetBody(log.StringValue(e.Message))

const sevOffset = logrus.Level(log.SeverityDebug) - logrus.DebugLevel
record.SetSeverity(log.Severity(e.Level + sevOffset))
record.SetSeverity(convertSeverity(e.Level))
record.AddAttributes(convertFields(e.Data)...)

return record
Expand All @@ -183,6 +183,30 @@ func convertFields(fields logrus.Fields) []log.KeyValue {
return kvs
}

func convertSeverity(level logrus.Level) log.Severity {
switch level {
case logrus.PanicLevel:
// PanicLevel is not supported by OpenTelemetry, use Fatal4 as the highest severity.
return log.SeverityFatal4
case logrus.FatalLevel:
return log.SeverityFatal
case logrus.ErrorLevel:
return log.SeverityError
case logrus.WarnLevel:
return log.SeverityWarn
case logrus.InfoLevel:
return log.SeverityInfo
case logrus.DebugLevel:
return log.SeverityDebug
case logrus.TraceLevel:
return log.SeverityTrace
default:
// If the level is not recognized, use SeverityUndefined as the lowest severity.
// we should never reach this point as logrus only uses the above levels.
return log.SeverityUndefined
}
}

func convertValue(v interface{}) log.Value {
switch v := v.(type) {
case bool:
Expand Down
76 changes: 71 additions & 5 deletions bridges/otellogrus/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestHookFire(t *testing.T) {

wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue(""), time.Time{}, 0, nil),
buildRecord(log.StringValue(""), time.Time{}, log.SeverityFatal4, nil),
},
},
},
Expand All @@ -173,18 +173,84 @@ func TestHookFire(t *testing.T) {
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue(""), now, 0, nil),
buildRecord(log.StringValue(""), now, log.SeverityFatal4, nil),
},
},
},
{
name: "emits a log entry with severity level",
name: "emits a log entry with panic severity level",
entry: &logrus.Entry{
Level: logrus.PanicLevel,
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue(""), time.Time{}, log.SeverityFatal4, nil),
},
},
},
{
name: "emits a log entry with fatal severity level",
entry: &logrus.Entry{
Level: logrus.FatalLevel,
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue(""), time.Time{}, log.SeverityTrace1, nil),
buildRecord(log.StringValue(""), time.Time{}, log.SeverityFatal, nil),
},
},
},
{
name: "emits a log entry with error severity level",
entry: &logrus.Entry{
Level: logrus.ErrorLevel,
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue(""), time.Time{}, log.SeverityError, nil),
},
},
},
{
name: "emits a log entry with warn severity level",
entry: &logrus.Entry{
Level: logrus.WarnLevel,
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue(""), time.Time{}, log.SeverityWarn, nil),
},
},
},
{
name: "emits a log entry with info severity level",
entry: &logrus.Entry{
Level: logrus.InfoLevel,
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue(""), time.Time{}, log.SeverityInfo, nil),
},
},
},
{
name: "emits a log entry with info severity level",
entry: &logrus.Entry{
Level: logrus.DebugLevel,
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue(""), time.Time{}, log.SeverityDebug, nil),
},
},
},
{
name: "emits a log entry with info severity level",
entry: &logrus.Entry{
Level: logrus.TraceLevel,
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue(""), time.Time{}, log.SeverityTrace, nil),
},
},
},
Expand All @@ -197,7 +263,7 @@ func TestHookFire(t *testing.T) {
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue(""), time.Time{}, 0, []log.KeyValue{
buildRecord(log.StringValue(""), time.Time{}, log.SeverityFatal4, []log.KeyValue{
log.String("hello", "world"),
}),
},
Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,11 @@ func ParseYAML(file []byte) (*OpenTelemetryConfiguration, error) {

return &cfg, nil
}

func toStringMap(pairs []NameStringValuePair) map[string]string {
output := make(map[string]string)
for _, v := range pairs {
output[v.Name] = *v.Value
}
return output
}
Loading

0 comments on commit e08dc29

Please sign in to comment.