grafana / docker-otel-lgtm

OpenTelemetry backend in a Docker image
Apache License 2.0
327 stars 62 forks source link

Replace lokiexporter to otlpexporter #44

Closed arukiidou closed 6 months ago

arukiidou commented 6 months ago

ingest endpoint

guide

https://grafana.com/docs/loki/latest/send-data/otel/#configure-the-opentelemetry-collector-to-write-logs-into-loki

source

https://github.com/grafana/loki/blob/19fef9355fdd46911611dbec25df0f5a4e397d31/pkg/loki/modules.go#L370

TESTS

✅OK

curl -H 'Content-Type: application/json' -X POST -v -s 'http://localhost:3100/otlp/v1/logs' --data-raw '{
...
}'

# *   Trying ::1...
# * TCP_NODELAY set
# * Connected to localhost (::1) port 3100 (#0)
# > POST /otlp/v1/logs HTTP/1.1
# > Host: localhost:3100
# > User-Agent: curl/7.61.1
# > Accept: */*
# > Content-Type: application/json
# > Content-Length: 2844
# > Expect: 100-continue
# > 
# < HTTP/1.1 100 Continue
# * We are completely uploaded and fine
# < HTTP/1.1 204 No Content
# < Date: Wed, 15 May 2024 09:55:17 GMT
# < 
# * Connection #0 to host localhost left intact

image

see: https://github.com/open-telemetry/opentelemetry-proto/blob/main/examples/logs.json

{
  "resourceLogs": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "stringValue": "rolldice"
            }
          },
          {
            "key": "job",
            "value": {
              "stringValue": "rolldice"
            }
          }
        ]
      },
      "scopeLogs": [
        {
          "scope": {
            "name": "my.library",
            "version": "1.0.0",
            "attributes": [
              {
                "key": "my.scope.attribute",
                "value": {
                  "stringValue": "some scope attribute"
                }
              }
            ]
          },
          "logRecords": [
            {
              "timeUnixNano": "1715766897500000111",
              "observedTimeUnixNano": "1715766897500000111",
              "severityNumber": 10,
              "severityText": "Information",
              "traceId": "c29e156486ccf3d30dde0491b4429d23",
              "spanId": "92e790ce6a007caa",
              "body": {
                "stringValue": "Example log record"
              },
              "attributes": [
                {
                  "key": "string.attribute",
                  "value": {
                    "stringValue": "some string"
                  }
                },
                {
                  "key": "boolean.attribute",
                  "value": {
                    "boolValue": true
                  }
                },
                {
                  "key": "int.attribute",
                  "value": {
                    "intValue": "10"
                  }
                },
                {
                  "key": "double.attribute",
                  "value": {
                    "doubleValue": 637.704
                  }
                },
                {
                  "key": "array.attribute",
                  "value": {
                    "arrayValue": {
                      "values": [
                        {
                          "stringValue": "many"
                        },
                        {
                          "stringValue": "values"
                        }
                      ]
                    }
                  }
                },
                {
                  "key": "map.attribute",
                  "value": {
                    "kvlistValue": {
                      "values": [
                        {
                          "key": "some.map.key",
                          "value": {
                            "stringValue": "some value"
                          }
                        }
                      ]
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}
arukiidou commented 6 months ago

send logs to opentelemetry-collector endpoint

curl -H 'Content-Type: application/json' -X POST -v -s 'http://localhost:4318/v1/logs' --data-raw '{
...
}'

# * Trying ::1...
# * TCP_NODELAY set
# * Connected to localhost (::1) port 4318 (#0)
# > POST /v1/logs HTTP/1.1
# > Host: localhost:4318
# > User-Agent: curl/7.61.1
# > Accept: */*
# > Content-Type: application/json
# > Content-Length: 2843
# > Expect: 100-continue
# > 
# < HTTP/1.1 100 Continue
# * We are completely uploaded and fine
# < HTTP/1.1 200 OK
# < Content-Type: application/json
# < Date: Wed, 15 May 2024 14:25:56 GMT
# < Content-Length: 21
# < 
# * Connection #0 to host localhost left intact
# {"partialSuccess":{}}