-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add preconfigured support for Smart Agent
- Loading branch information
1 parent
70ba63a
commit 29418cf
Showing
10 changed files
with
153 additions
and
17 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
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 @@ | ||
Gemfile.lock |
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,6 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "opentelemetry-exporter-jaeger" | ||
gem "splunk-otel", path: "../../" |
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,8 @@ | ||
version: "3" | ||
services: | ||
otel: | ||
image: quay.io/signalfx/signalfx-agent:5 | ||
ports: | ||
- 9080:9080 | ||
volumes: | ||
- ./smart-agent-config.yaml:/etc/signalfx/agent.yaml |
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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rubygems" | ||
require "bundler/setup" | ||
Bundler.require(:default) | ||
|
||
Splunk::Otel.configure do |configurator| | ||
$configurator = configurator # rubocop:disable Style/GlobalVars | ||
|
||
class << configurator | ||
def test_shutdown | ||
@span_processors.each(&:shutdown) | ||
end | ||
end | ||
end | ||
|
||
tracer = OpenTelemetry.tracer_provider.tracer("test", "1.0") | ||
tracer.in_span("test-span") do | ||
puts "test-span execution" | ||
end | ||
|
||
$configurator.test_shutdown # rubocop:disable Style/GlobalVars |
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,5 @@ | ||
signalFxAccessToken: "" | ||
ingestUrl: "https://ingest.lab0.signalfx.com" | ||
signalFxRealm: "lab0" | ||
monitors: | ||
- type: trace-forwarder |
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,54 @@ | ||
# frozen_string_literal: true | ||
|
||
module Splunk | ||
module Otel | ||
OUR_EXPORTERS_KEYS = ["jaeger-thrift-splunk"].freeze | ||
private_constant :OUR_EXPORTERS_KEYS | ||
|
||
# internal module for allowing our exporters to be set via ENV | ||
module ExporterExtensions | ||
def effective_splunk_jaeger_endpoint | ||
return "https://ingest.#{ENV["SPLUNK_REALM"]}.signalfx.com/v1/trace" if ENV["SPLUNK_REALM"] | ||
return ENV["OTEL_EXPORTER_JAEGER_ENDPOINT"] if ENV["OTEL_EXPORTER_JAEGER_ENDPOINT"] | ||
|
||
"http://127.0.0.1:9080/v1/trace" | ||
end | ||
|
||
def wrapped_exporters_from_env | ||
original_env_value = ENV.fetch("OTEL_TRACES_EXPORTER", "otlp") | ||
exporters_keys = original_env_value.split(",").map(&:strip) | ||
non_proprietary_exporters_keys = exporters_keys - OUR_EXPORTERS_KEYS | ||
|
||
ENV["OTEL_TRACES_EXPORTER"] = non_proprietary_exporters_keys.join(",") | ||
original_exporters = super | ||
ENV["OTEL_TRACES_EXPORTER"] = original_env_value | ||
|
||
original_exporters + proprietary_exporters(exporters_keys) | ||
end | ||
|
||
def proprietary_exporters(exporters_keys) | ||
(exporters_keys & OUR_EXPORTERS_KEYS).map do |exporter_key| | ||
case exporter_key | ||
when "jaeger-thrift-splunk" | ||
args = { | ||
endpoint: effective_splunk_jaeger_endpoint | ||
} | ||
fetch_exporter_with_args("jaeger-thrift-splunk", "OpenTelemetry::Exporter::Jaeger::CollectorExporter", | ||
**args) | ||
end | ||
end.compact | ||
end | ||
|
||
def fetch_exporter_with_args(name, class_name, **args) | ||
# TODO: warn if jaeger exporter gem is not present | ||
exporter = Kernel.const_get(class_name).new(**args) | ||
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new exporter | ||
rescue NameError | ||
OpenTelemetry.logger.warn "The #{name} exporter cannot be configured" \ | ||
"- please add opentelemetry-exporter-#{name} to your Gemfile" \ | ||
", spans will not be exported.." | ||
nil | ||
end | ||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "opentelemetry/sdk" | ||
require "opentelemetry-exporter-jaeger" | ||
|
||
module Splunk | ||
class OtelProprietaryExportersTest < Test::Unit::TestCase | ||
def setup | ||
with_env("OTEL_TRACES_EXPORTER" => "jaeger-thrift-splunk") do | ||
Splunk::Otel.configure | ||
end | ||
end | ||
|
||
def teardown | ||
OpenTelemetry.tracer_provider.shutdown | ||
end | ||
|
||
test "check that jaeger exporter is present" do | ||
processors = OpenTelemetry.tracer_provider.instance_variable_get("@span_processors") | ||
exporter = processors[0].instance_variable_get("@exporter") | ||
assert_instance_of OpenTelemetry::Exporter::Jaeger::CollectorExporter, exporter | ||
end | ||
end | ||
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