-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: opentelemetry + logging (#311)
This patch adds support for opentelemetry tracing as well as better logging. The included docker-compose includes grafana tempo to view the opentelemetry traces
- Loading branch information
Showing
22 changed files
with
398 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,5 @@ result | |
/priv/plts/*.plt | ||
/priv/plts/*.plt.hash | ||
node_modules | ||
|
||
tempo-data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Config | ||
|
||
if System.get_env("NEXTLS_OTEL") == "1" do | ||
config :next_ls, | ||
otel: true | ||
|
||
config :opentelemetry_exporter, | ||
otlp_protocol: :grpc, | ||
otlp_endpoint: "http://localhost:4317" | ||
else | ||
config :opentelemetry, traces_exporter: :none | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import Config | ||
|
||
config :logger, :default_handler, config: [type: :standard_error] | ||
|
||
config :gen_lsp, :exit_on_end, false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
version: "3" | ||
services: | ||
tempo: | ||
image: grafana/tempo:latest | ||
command: [ "-config.file=/etc/tempo.yaml" ] | ||
volumes: | ||
- ./tempo.yaml:/etc/tempo.yaml | ||
- ./tempo-data:/tmp/tempo | ||
ports: | ||
- "14268:14268" # jaeger ingest | ||
- "3200:3200" # tempo | ||
# - "4317:4317" # otlp grpc | ||
# - "4318:4318" # otlp http | ||
- "9411:9411" # zipkin | ||
|
||
otel-collector: | ||
image: otel/opentelemetry-collector:0.61.0 | ||
command: [ "--config=/etc/otel-collector.yaml" ] | ||
volumes: | ||
- ./otel-collector.yaml:/etc/otel-collector.yaml | ||
ports: | ||
- "4317:4317" # otlp grpc | ||
- "4318:4318" # otlp http | ||
|
||
prometheus: | ||
image: prom/prometheus:latest | ||
command: | ||
- --config.file=/etc/prometheus.yaml | ||
- --web.enable-remote-write-receiver | ||
- --enable-feature=exemplar-storage | ||
volumes: | ||
- ./prometheus.yaml:/etc/prometheus.yaml | ||
ports: | ||
- "9090:9090" | ||
|
||
grafana: | ||
image: grafana/grafana:9.4.3 | ||
volumes: | ||
- ./grafana-datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml | ||
environment: | ||
- GF_AUTH_ANONYMOUS_ENABLED=true | ||
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin | ||
- GF_AUTH_DISABLE_LOGIN_FORM=true | ||
- GF_FEATURE_TOGGLES_ENABLE=traceqlEditor | ||
ports: | ||
- "3000:3000" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: 1 | ||
|
||
datasources: | ||
- name: Prometheus | ||
type: prometheus | ||
uid: prometheus | ||
access: proxy | ||
orgId: 1 | ||
url: http://prometheus:9090 | ||
basicAuth: false | ||
isDefault: false | ||
version: 1 | ||
editable: false | ||
jsonData: | ||
httpMethod: GET | ||
- name: Tempo | ||
type: tempo | ||
access: proxy | ||
orgId: 1 | ||
url: http://tempo:3200 | ||
basicAuth: false | ||
isDefault: true | ||
version: 1 | ||
editable: false | ||
apiVersion: 1 | ||
uid: tempo | ||
jsonData: | ||
httpMethod: GET | ||
serviceMap: | ||
datasourceUid: prometheus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
defmodule NextLS.OpentelemetryGenLSP do | ||
@moduledoc false | ||
require Logger | ||
|
||
@tracer_id __MODULE__ | ||
|
||
def setup do | ||
:ok = | ||
:telemetry.attach_many( | ||
"gen_lsp-handler", | ||
[ | ||
[:gen_lsp, :notify, :server, :start], | ||
[:gen_lsp, :notify, :server, :stop], | ||
[:gen_lsp, :request, :server, :start], | ||
[:gen_lsp, :request, :server, :stop], | ||
[:gen_lsp, :request, :client, :start], | ||
[:gen_lsp, :request, :client, :stop], | ||
[:gen_lsp, :notification, :client, :start], | ||
[:gen_lsp, :notification, :client, :stop], | ||
[:gen_lsp, :handle_request, :start], | ||
[:gen_lsp, :handle_request, :stop], | ||
[:gen_lsp, :handle_notification, :start], | ||
[:gen_lsp, :handle_notification, :stop], | ||
[:gen_lsp, :handle_info, :start], | ||
[:gen_lsp, :handle_info, :stop] | ||
# [:gen_lsp, :buffer, :outgoing, :start], | ||
# [:gen_lsp, :buffer, :outgoing, :stop], | ||
# [:gen_lsp, :buffer, :incoming, :start], | ||
# [:gen_lsp, :buffer, :incoming, :stop] | ||
], | ||
&__MODULE__.process/4, | ||
nil | ||
) | ||
end | ||
|
||
def process([:gen_lsp, type1, type2, :start], _measurements, metadata, _config) do | ||
OpentelemetryTelemetry.start_telemetry_span( | ||
@tracer_id, | ||
:"gen_lsp.#{type1}.#{type2}", | ||
metadata, | ||
%{kind: :server, attributes: metadata} | ||
) | ||
end | ||
|
||
def process([:gen_lsp, handle, :start], _measurements, metadata, _config) do | ||
if handle in [:handle_request, :handle_notification] do | ||
# set attribute for parent span | ||
OpenTelemetry.Tracer.set_attribute(:method, metadata[:method]) | ||
end | ||
|
||
OpentelemetryTelemetry.start_telemetry_span( | ||
@tracer_id, | ||
:"next_ls.#{handle}", | ||
metadata, | ||
%{kind: :server, attributes: metadata} | ||
) | ||
end | ||
|
||
def process([:gen_lsp, _, _, :stop], _measurements, metadata, _config) do | ||
OpentelemetryTelemetry.set_current_telemetry_span(@tracer_id, metadata) | ||
OpentelemetryTelemetry.end_telemetry_span(@tracer_id, metadata) | ||
end | ||
|
||
def process([:gen_lsp, _, :stop], _measurements, metadata, _config) do | ||
OpentelemetryTelemetry.set_current_telemetry_span(@tracer_id, metadata) | ||
OpentelemetryTelemetry.end_telemetry_span(@tracer_id, metadata) | ||
end | ||
end |
Oops, something went wrong.