solarwinds_apm 6.1.1 → 7.0.0.prev1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +53 -4
- data/lib/rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb +0 -4
- data/lib/solarwinds_apm/api/current_trace_info.rb +10 -6
- data/lib/solarwinds_apm/api/custom_instrumentation.rb +80 -0
- data/lib/solarwinds_apm/api/custom_metrics.rb +8 -25
- data/lib/solarwinds_apm/api/tracing.rb +12 -27
- data/lib/solarwinds_apm/api/transaction_name.rb +6 -10
- data/lib/solarwinds_apm/api.rb +2 -0
- data/lib/solarwinds_apm/config.rb +1 -1
- data/lib/solarwinds_apm/constants.rb +1 -0
- data/lib/solarwinds_apm/noop/api.rb +5 -2
- data/lib/solarwinds_apm/noop.rb +0 -24
- data/lib/solarwinds_apm/opentelemetry/otlp_processor.rb +90 -69
- data/lib/solarwinds_apm/opentelemetry/solarwinds_propagator.rb +0 -2
- data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +5 -4
- data/lib/solarwinds_apm/opentelemetry.rb +5 -7
- data/lib/solarwinds_apm/otel_native_config.rb +177 -0
- data/lib/solarwinds_apm/patch/README.md +15 -0
- data/lib/solarwinds_apm/patch/tag_sql/sw_dbo_utils.rb +35 -0
- data/lib/solarwinds_apm/patch/tag_sql/sw_mysql2_patch.rb +1 -12
- data/lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb +39 -0
- data/lib/solarwinds_apm/patch/tag_sql_patch.rb +2 -0
- data/lib/solarwinds_apm/{noop/metadata.rb → sampling/dice.rb} +19 -17
- data/lib/solarwinds_apm/sampling/http_sampler.rb +87 -0
- data/lib/solarwinds_apm/sampling/json_sampler.rb +52 -0
- data/lib/solarwinds_apm/sampling/metrics.rb +38 -0
- data/lib/solarwinds_apm/sampling/oboe_sampler.rb +348 -0
- data/lib/solarwinds_apm/sampling/sampler.rb +197 -0
- data/lib/solarwinds_apm/sampling/sampling_constants.rb +127 -0
- data/lib/solarwinds_apm/sampling/sampling_patch.rb +49 -0
- data/lib/solarwinds_apm/sampling/setting_example.txt +1 -0
- data/lib/solarwinds_apm/{noop/context.rb → sampling/settings.rb} +14 -25
- data/lib/solarwinds_apm/sampling/token_bucket.rb +126 -0
- data/lib/solarwinds_apm/sampling/trace_options.rb +100 -0
- data/lib/solarwinds_apm/{patch.rb → sampling.rb} +20 -4
- data/lib/solarwinds_apm/{noop/span.rb → support/aws_resource_detector.rb} +5 -18
- data/lib/solarwinds_apm/support/logger_formatter.rb +1 -1
- data/lib/solarwinds_apm/support/logging_log_event.rb +1 -1
- data/lib/solarwinds_apm/support/lumberjack_formatter.rb +1 -1
- data/lib/solarwinds_apm/support/otlp_endpoint.rb +99 -0
- data/lib/solarwinds_apm/support/resource_detector/aws/beanstalk.rb +51 -0
- data/lib/solarwinds_apm/support/resource_detector/aws/ec2.rb +145 -0
- data/lib/solarwinds_apm/support/resource_detector/aws/ecs.rb +173 -0
- data/lib/solarwinds_apm/support/resource_detector/aws/eks.rb +174 -0
- data/lib/solarwinds_apm/support/resource_detector/aws/lambda.rb +66 -0
- data/lib/solarwinds_apm/support/resource_detector.rb +192 -0
- data/lib/solarwinds_apm/support/service_key_checker.rb +12 -6
- data/lib/solarwinds_apm/support/transaction_settings.rb +6 -0
- data/lib/solarwinds_apm/support/txn_name_manager.rb +54 -9
- data/lib/solarwinds_apm/support/utils.rb +9 -0
- data/lib/solarwinds_apm/support.rb +3 -4
- data/lib/solarwinds_apm/version.rb +4 -4
- data/lib/solarwinds_apm.rb +27 -73
- metadata +105 -50
- data/ext/oboe_metal/extconf.rb +0 -168
- data/ext/oboe_metal/lib/liboboe-1.0-aarch64.so.sha256 +0 -1
- data/ext/oboe_metal/lib/liboboe-1.0-alpine-aarch64.so.sha256 +0 -1
- data/ext/oboe_metal/lib/liboboe-1.0-alpine-x86_64.so.sha256 +0 -1
- data/ext/oboe_metal/lib/liboboe-1.0-lambda-aarch64.so.sha256 +0 -1
- data/ext/oboe_metal/lib/liboboe-1.0-lambda-x86_64.so.sha256 +0 -1
- data/ext/oboe_metal/lib/liboboe-1.0-x86_64.so.sha256 +0 -1
- data/ext/oboe_metal/src/VERSION +0 -1
- data/ext/oboe_metal/src/bson/bson.h +0 -220
- data/ext/oboe_metal/src/bson/platform_hacks.h +0 -91
- data/ext/oboe_metal/src/init_solarwinds_apm.cc +0 -18
- data/ext/oboe_metal/src/oboe.h +0 -930
- data/ext/oboe_metal/src/oboe_api.cpp +0 -793
- data/ext/oboe_metal/src/oboe_api.h +0 -621
- data/ext/oboe_metal/src/oboe_debug.h +0 -17
- data/ext/oboe_metal/src/oboe_swig_wrap.cc +0 -10954
- data/lib/oboe_metal.rb +0 -187
- data/lib/solarwinds_apm/cert/star.appoptics.com.issuer.crt +0 -24
- data/lib/solarwinds_apm/oboe_init_options.rb +0 -222
- data/lib/solarwinds_apm/opentelemetry/solarwinds_exporter.rb +0 -239
- data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +0 -174
- data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +0 -333
- data/lib/solarwinds_apm/otel_config.rb +0 -174
- data/lib/solarwinds_apm/otel_lambda_config.rb +0 -56
- data/lib/solarwinds_apm/patch/dummy_patch.rb +0 -12
- data/lib/solarwinds_apm/support/oboe_tracing_mode.rb +0 -33
- data/lib/solarwinds_apm/support/support_report.rb +0 -99
- data/lib/solarwinds_apm/support/swomarginalia/LICENSE +0 -20
- data/lib/solarwinds_apm/support/swomarginalia/README.md +0 -46
- data/lib/solarwinds_apm/support/swomarginalia/comment.rb +0 -206
- data/lib/solarwinds_apm/support/swomarginalia/formatter.rb +0 -20
- data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +0 -55
- data/lib/solarwinds_apm/support/swomarginalia/railtie.rb +0 -24
- data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +0 -89
- data/lib/solarwinds_apm/support/transaction_cache.rb +0 -57
- data/lib/solarwinds_apm/support/x_trace_options.rb +0 -138
@@ -0,0 +1,174 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
require 'net/http'
|
8
|
+
require 'json'
|
9
|
+
require 'openssl'
|
10
|
+
require 'uri'
|
11
|
+
require 'opentelemetry/common'
|
12
|
+
require 'opentelemetry/semantic_conventions/resource'
|
13
|
+
|
14
|
+
module OpenTelemetry
|
15
|
+
module Resource
|
16
|
+
module Detector
|
17
|
+
module AWS
|
18
|
+
# EKS contains detect class method for determining EKS resource attributes
|
19
|
+
module EKS
|
20
|
+
extend self
|
21
|
+
|
22
|
+
# Container ID length from cgroup file
|
23
|
+
CONTAINER_ID_LENGTH = 64
|
24
|
+
|
25
|
+
# HTTP request timeout in seconds
|
26
|
+
HTTP_TIMEOUT = 5
|
27
|
+
|
28
|
+
# Kubernetes token and certificate paths
|
29
|
+
TOKEN_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/token'
|
30
|
+
CERT_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'
|
31
|
+
|
32
|
+
# Kubernetes API paths
|
33
|
+
AWS_AUTH_PATH = '/api/v1/namespaces/kube-system/configmaps/aws-auth'
|
34
|
+
CLUSTER_INFO_PATH = '/api/v1/namespaces/amazon-cloudwatch/configmaps/cluster-info'
|
35
|
+
|
36
|
+
# Create a constant for resource semantic conventions
|
37
|
+
RESOURCE = ::OpenTelemetry::SemanticConventions::Resource
|
38
|
+
|
39
|
+
def detect
|
40
|
+
# Return empty resource if not running on K8s
|
41
|
+
return ::OpenTelemetry::SDK::Resources::Resource.create({}) unless k8s?
|
42
|
+
|
43
|
+
resource_attributes = {}
|
44
|
+
|
45
|
+
begin
|
46
|
+
# Get K8s credentials
|
47
|
+
cred_value = k8s_cred_value
|
48
|
+
|
49
|
+
# Verify this is an EKS cluster
|
50
|
+
unless eks?(cred_value)
|
51
|
+
::OpenTelemetry.logger.debug('Could not confirm process is running on EKS')
|
52
|
+
return ::OpenTelemetry::SDK::Resources::Resource.create({})
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get cluster name and container ID
|
56
|
+
cluster_name_val = cluster_name(cred_value)
|
57
|
+
container_id_val = container_id
|
58
|
+
|
59
|
+
if container_id_val.empty? && cluster_name_val.empty?
|
60
|
+
::OpenTelemetry.logger.debug('Neither cluster name nor container ID found on EKS process')
|
61
|
+
return ::OpenTelemetry::SDK::Resources::Resource.create({})
|
62
|
+
end
|
63
|
+
|
64
|
+
# Set resource attributes
|
65
|
+
resource_attributes[RESOURCE::CLOUD_PROVIDER] = 'aws'
|
66
|
+
resource_attributes[RESOURCE::CLOUD_PLATFORM] = 'aws_eks'
|
67
|
+
resource_attributes[RESOURCE::K8S_CLUSTER_NAME] = cluster_name_val unless cluster_name_val.empty?
|
68
|
+
resource_attributes[RESOURCE::CONTAINER_ID] = container_id_val unless container_id_val.empty?
|
69
|
+
rescue StandardError => e
|
70
|
+
::OpenTelemetry.logger.debug("EKS resource detection failed: #{e.message}")
|
71
|
+
return ::OpenTelemetry::SDK::Resources::Resource.create({})
|
72
|
+
end
|
73
|
+
|
74
|
+
resource_attributes.delete_if { |_key, value| value.nil? || value.empty? }
|
75
|
+
::OpenTelemetry::SDK::Resources::Resource.create(resource_attributes)
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# Check if running on K8s
|
81
|
+
#
|
82
|
+
# @return [Boolean] true if running on K8s
|
83
|
+
def k8s?
|
84
|
+
File.exist?(TOKEN_PATH) && File.exist?(CERT_PATH)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Get K8s token
|
88
|
+
#
|
89
|
+
# @return [String] K8s token
|
90
|
+
# @raise [StandardError] if token could not be read
|
91
|
+
def k8s_cred_value
|
92
|
+
token = File.read(TOKEN_PATH).strip
|
93
|
+
"Bearer #{token}"
|
94
|
+
rescue StandardError => e
|
95
|
+
::OpenTelemetry.logger.debug("Failed to get k8s token: #{e.message}")
|
96
|
+
raise e
|
97
|
+
end
|
98
|
+
|
99
|
+
# Check if running on EKS
|
100
|
+
#
|
101
|
+
# @param cred_value [String] K8s credentials
|
102
|
+
# @return [Boolean] true if running on EKS
|
103
|
+
def eks?(cred_value)
|
104
|
+
# Just try to to access the aws-auth configmap
|
105
|
+
# If it exists and we can access it, we're on EKS
|
106
|
+
aws_http_request(AWS_AUTH_PATH, cred_value)
|
107
|
+
true
|
108
|
+
rescue StandardError
|
109
|
+
false
|
110
|
+
end
|
111
|
+
|
112
|
+
# Get EKS cluster name
|
113
|
+
#
|
114
|
+
# @param cred_value [String] K8s credentials
|
115
|
+
# @return [String] Cluster name or empty string if not found
|
116
|
+
def cluster_name(cred_value)
|
117
|
+
begin
|
118
|
+
response = aws_http_request(CLUSTER_INFO_PATH, cred_value)
|
119
|
+
cluster_info = JSON.parse(response)
|
120
|
+
return cluster_info['data']['cluster.name'] if cluster_info['data'] && cluster_info['data']['cluster.name']
|
121
|
+
rescue StandardError => e
|
122
|
+
::OpenTelemetry.logger.debug("Cannot get cluster name on EKS: #{e.message}")
|
123
|
+
end
|
124
|
+
''
|
125
|
+
end
|
126
|
+
|
127
|
+
# Get container ID from cgroup file
|
128
|
+
#
|
129
|
+
# @return [String] Container ID or empty string if not found
|
130
|
+
def container_id
|
131
|
+
begin
|
132
|
+
File.open('/proc/self/cgroup', 'r') do |file|
|
133
|
+
file.each_line do |line|
|
134
|
+
line = line.strip
|
135
|
+
# Look for container ID (64 chars) at the end of the line
|
136
|
+
return line[-CONTAINER_ID_LENGTH..] if line.length > CONTAINER_ID_LENGTH
|
137
|
+
end
|
138
|
+
end
|
139
|
+
rescue StandardError => e
|
140
|
+
::OpenTelemetry.logger.debug("Failed to get container ID on EKS: #{e.message}")
|
141
|
+
end
|
142
|
+
''
|
143
|
+
end
|
144
|
+
|
145
|
+
# Make HTTP GET request to K8s API
|
146
|
+
#
|
147
|
+
# @param path [String] API path
|
148
|
+
# @param cred_value [String] Authorization header value
|
149
|
+
# @return [String] Response body
|
150
|
+
# @raise [StandardError] if request fails
|
151
|
+
def aws_http_request(path, cred_value)
|
152
|
+
uri = URI.parse("https://kubernetes.default.svc#{path}")
|
153
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
154
|
+
http.use_ssl = true
|
155
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
156
|
+
http.ca_file = CERT_PATH
|
157
|
+
http.open_timeout = HTTP_TIMEOUT
|
158
|
+
http.read_timeout = HTTP_TIMEOUT
|
159
|
+
|
160
|
+
request = Net::HTTP::Get.new(uri)
|
161
|
+
request['Authorization'] = cred_value
|
162
|
+
|
163
|
+
::OpenTelemetry::Common::Utilities.untraced do
|
164
|
+
response = http.request(request)
|
165
|
+
raise "HTTP request failed with status #{response.code}" unless response.is_a?(Net::HTTPSuccess)
|
166
|
+
|
167
|
+
response.body
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
require 'opentelemetry/semantic_conventions/resource'
|
8
|
+
|
9
|
+
module OpenTelemetry
|
10
|
+
module Resource
|
11
|
+
module Detector
|
12
|
+
module AWS
|
13
|
+
# Lambda contains detect class method for determining Lambda resource attributes
|
14
|
+
module Lambda
|
15
|
+
extend self
|
16
|
+
|
17
|
+
# Create a constant for resource semantic conventions
|
18
|
+
RESOURCE = ::OpenTelemetry::SemanticConventions::Resource
|
19
|
+
|
20
|
+
def detect
|
21
|
+
# Return empty resource if not running on Lambda
|
22
|
+
return ::OpenTelemetry::SDK::Resources::Resource.create({}) unless lambda_environment?
|
23
|
+
|
24
|
+
resource_attributes = {}
|
25
|
+
|
26
|
+
begin
|
27
|
+
# Set Lambda-specific attributes from environment variables
|
28
|
+
resource_attributes[RESOURCE::CLOUD_PROVIDER] = 'aws'
|
29
|
+
resource_attributes[RESOURCE::CLOUD_PLATFORM] = 'aws_lambda'
|
30
|
+
resource_attributes[RESOURCE::CLOUD_REGION] = ENV.fetch('AWS_REGION', nil)
|
31
|
+
resource_attributes[RESOURCE::FAAS_NAME] = ENV.fetch('AWS_LAMBDA_FUNCTION_NAME', nil)
|
32
|
+
resource_attributes[RESOURCE::FAAS_VERSION] = ENV.fetch('AWS_LAMBDA_FUNCTION_VERSION', nil)
|
33
|
+
resource_attributes[RESOURCE::FAAS_INSTANCE] = ENV.fetch('AWS_LAMBDA_LOG_STREAM_NAME', nil)
|
34
|
+
|
35
|
+
# Convert memory size to integer
|
36
|
+
resource_attributes[RESOURCE::FAAS_MAX_MEMORY] = ENV['AWS_LAMBDA_FUNCTION_MEMORY_SIZE'].to_i if ENV['AWS_LAMBDA_FUNCTION_MEMORY_SIZE']
|
37
|
+
rescue StandardError => e
|
38
|
+
::OpenTelemetry.handle_error(exception: e, message: 'Lambda resource detection failed')
|
39
|
+
return ::OpenTelemetry::SDK::Resources::Resource.create({})
|
40
|
+
end
|
41
|
+
|
42
|
+
# Filter out nil or empty values
|
43
|
+
# Note: we need to handle integers differently since they don't respond to empty?
|
44
|
+
resource_attributes.delete_if do |_key, value|
|
45
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
46
|
+
end
|
47
|
+
|
48
|
+
::OpenTelemetry::SDK::Resources::Resource.create(resource_attributes)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
# Determines if the current environment is AWS Lambda
|
54
|
+
#
|
55
|
+
# @return [Boolean] true if running on AWS Lambda
|
56
|
+
def lambda_environment?
|
57
|
+
# Check for Lambda-specific environment variables
|
58
|
+
!ENV['AWS_LAMBDA_FUNCTION_NAME'].nil? &&
|
59
|
+
!ENV['AWS_LAMBDA_FUNCTION_VERSION'].nil? &&
|
60
|
+
!ENV['AWS_LAMBDA_LOG_STREAM_NAME'].nil?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# © 2023 SolarWinds Worldwide, LLC. All rights reserved.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
#
|
7
|
+
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
8
|
+
|
9
|
+
require 'net/http'
|
10
|
+
require 'uri'
|
11
|
+
require 'json'
|
12
|
+
require 'socket'
|
13
|
+
require 'securerandom'
|
14
|
+
require 'opentelemetry/resource/detector/azure'
|
15
|
+
require 'opentelemetry/resource/detector/container'
|
16
|
+
require_relative 'resource_detector/aws/ec2'
|
17
|
+
|
18
|
+
module SolarWindsAPM
|
19
|
+
# ResourceDetector
|
20
|
+
# Usage:
|
21
|
+
# require 'opentelemetry/sdk'
|
22
|
+
# require 'opentelemetry/resource/detector'
|
23
|
+
# OpenTelemetry::SDK.configure do |c|
|
24
|
+
# c.resource = SolarWindsAPM::ResourceDetector.detect
|
25
|
+
# end
|
26
|
+
module ResourceDetector
|
27
|
+
K8S_PODNAME_PATH = '/etc/hostname'
|
28
|
+
K8S_NAMESPACE_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/namespace'
|
29
|
+
K8S_NAMESPACE_PATH_WIN = 'C:\\var\\run\\secrets\\kubernetes.io\\serviceaccount\\namespace'
|
30
|
+
K8S_MOUNTINFO_FILE = '/proc/self/mountinfo'
|
31
|
+
UID_REGEX = /[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}/i
|
32
|
+
|
33
|
+
SW_K8S_NAMESPACE_ENV = 'SW_K8S_POD_NAMESPACE'
|
34
|
+
SW_K8S_UID_ENV = 'SW_K8S_POD_UID'
|
35
|
+
SW_K8S_NAME_ENV = 'SW_K8S_POD_NAME'
|
36
|
+
|
37
|
+
UAMS_CLIENT_PATH = '/opt/solarwinds/uamsclient/var/uamsclientid'
|
38
|
+
UAMS_CLIENT_PATH_WIN = 'C:\\ProgramData\\SolarWinds\\UAMSClient\\uamsclientid'
|
39
|
+
UAMS_CLIENT_URL = 'http://127.0.0.1:2113/info/uamsclient'
|
40
|
+
UAMS_CLIENT_ID_FIELD = 'uamsclient_id'
|
41
|
+
|
42
|
+
def self.detect
|
43
|
+
uuid_attr = { ::OpenTelemetry::SemanticConventions::Resource::SERVICE_INSTANCE_ID => random_uuid }
|
44
|
+
attributes = ::OpenTelemetry::SDK::Resources::Resource.create(uuid_attr)
|
45
|
+
attributes = attributes.merge(detect_uams_client_id)
|
46
|
+
attributes = attributes.merge(detect_k8s_attributes)
|
47
|
+
attributes = attributes.merge(detect_ec2)
|
48
|
+
attributes = attributes.merge(detect_azure)
|
49
|
+
attributes.merge(detect_container)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.detect_uams_client_id
|
53
|
+
uams_client_final_path = windows? ? UAMS_CLIENT_PATH_WIN : UAMS_CLIENT_PATH
|
54
|
+
uams_client_id = nil
|
55
|
+
begin
|
56
|
+
uams_client_id = File.read(uams_client_final_path).strip
|
57
|
+
rescue StandardError => e
|
58
|
+
SolarWindsAPM.logger.debug "#{self.class}/#{__method__}] uams file retrieve error #{e.message}."
|
59
|
+
end
|
60
|
+
|
61
|
+
if uams_client_id.nil?
|
62
|
+
begin
|
63
|
+
url = URI(UAMS_CLIENT_URL)
|
64
|
+
|
65
|
+
response = nil
|
66
|
+
::OpenTelemetry::Common::Utilities.untraced do
|
67
|
+
http = Net::HTTP.new(url.host, url.port)
|
68
|
+
request = Net::HTTP::Get.new(url)
|
69
|
+
response = http.request(request)
|
70
|
+
end
|
71
|
+
|
72
|
+
raise 'Response returned non-200 status code' unless response&.code.to_i == 200
|
73
|
+
|
74
|
+
uams_metadata = JSON.parse(response.body)
|
75
|
+
uams_client_id = uams_metadata&.fetch(UAMS_CLIENT_ID_FIELD)
|
76
|
+
rescue StandardError => e
|
77
|
+
SolarWindsAPM.logger.debug "#{self.class}/#{__method__}] uams api retrieve error #{e.message}."
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
resource_attributes = {
|
82
|
+
'sw.uams.client.id' => uams_client_id,
|
83
|
+
'host.id' => uams_client_id
|
84
|
+
}
|
85
|
+
|
86
|
+
SolarWindsAPM.logger.debug "#{self.class}/#{__method__}] retrieved resource_attributes: #{resource_attributes.inspect}."
|
87
|
+
::OpenTelemetry::SDK::Resources::Resource.create(resource_attributes)
|
88
|
+
rescue StandardError => e
|
89
|
+
SolarWindsAPM.logger.debug "#{self.class}/#{__method__}] detect_uams_client_id failed. Error: #{e.message}."
|
90
|
+
::OpenTelemetry::SDK::Resources::Resource.create({})
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.detect_k8s_attributes
|
94
|
+
unless ENV['KUBERNETES_SERVICE_HOST'] && ENV['KUBERNETES_SERVICE_PORT']
|
95
|
+
SolarWindsAPM.logger.debug { "Can't read environment variable (KUBERNETES_SERVICE_HOST/KUBERNETES_SERVICE_PORT). It's likely not in kubernetes pod environment. No K8S resource detection." }
|
96
|
+
return ::OpenTelemetry::SDK::Resources::Resource.create({})
|
97
|
+
end
|
98
|
+
|
99
|
+
pod_name = ENV.fetch(SW_K8S_NAME_ENV, nil)
|
100
|
+
if pod_name.nil?
|
101
|
+
pod_name = Socket.gethostname
|
102
|
+
else
|
103
|
+
SolarWindsAPM.logger.debug { "read pod name from env #{pod_name}" }
|
104
|
+
end
|
105
|
+
|
106
|
+
pod_namespace = ENV.fetch(SW_K8S_NAMESPACE_ENV, nil)
|
107
|
+
if pod_namespace.nil?
|
108
|
+
begin
|
109
|
+
k8s_namspace_final_path = windows? ? K8S_NAMESPACE_PATH_WIN : K8S_NAMESPACE_PATH
|
110
|
+
pod_namespace = File.read(k8s_namspace_final_path).strip
|
111
|
+
SolarWindsAPM.logger.debug { 'read pod namespace from file' }
|
112
|
+
rescue StandardError => e
|
113
|
+
SolarWindsAPM.logger.debug { "can't read pod namespace #{e.message}" }
|
114
|
+
end
|
115
|
+
else
|
116
|
+
SolarWindsAPM.logger.debug { "read pod namespace from env #{pod_namespace}" }
|
117
|
+
end
|
118
|
+
|
119
|
+
pod_uid = ENV.fetch(SW_K8S_UID_ENV, nil)
|
120
|
+
if pod_uid.nil?
|
121
|
+
begin
|
122
|
+
File.open(K8S_MOUNTINFO_FILE) do |file|
|
123
|
+
file.each_line do |line|
|
124
|
+
fields = line.split
|
125
|
+
next if fields.size < 10
|
126
|
+
|
127
|
+
id, parent_id, _, root = fields
|
128
|
+
next unless safe_integer?(id) && safe_integer?(parent_id)
|
129
|
+
next unless root.include?('kube')
|
130
|
+
|
131
|
+
matches = UID_REGEX.match(root)
|
132
|
+
pod_uid = matches[0] if matches
|
133
|
+
break if pod_uid
|
134
|
+
end
|
135
|
+
end
|
136
|
+
rescue StandardError => e
|
137
|
+
SolarWindsAPM.logger.debug { "can't read pod uid #{e.message}" }
|
138
|
+
end
|
139
|
+
else
|
140
|
+
SolarWindsAPM.logger.debug { "read pod uid from env #{pod_uid}" }
|
141
|
+
end
|
142
|
+
|
143
|
+
resource_attributes = {
|
144
|
+
::OpenTelemetry::SemanticConventions::Resource::K8S_NAMESPACE_NAME => pod_namespace,
|
145
|
+
::OpenTelemetry::SemanticConventions::Resource::K8S_POD_NAME => pod_name,
|
146
|
+
::OpenTelemetry::SemanticConventions::Resource::K8S_POD_UID => pod_uid
|
147
|
+
}
|
148
|
+
|
149
|
+
resource_attributes.compact!
|
150
|
+
SolarWindsAPM.logger.debug { "#{self.class}/#{__method__}] retrieved resource_attributes: #{resource_attributes.inspect}." }
|
151
|
+
::OpenTelemetry::SDK::Resources::Resource.create(resource_attributes)
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.detect_ec2
|
155
|
+
attribute = ::OpenTelemetry::Resource::Detector::AWS::EC2.detect
|
156
|
+
SolarWindsAPM.logger.debug { "#{self.class}/#{__method__}] retrieved resource_attributes: #{attribute.instance_variable_get(:@attributes)}" }
|
157
|
+
attribute
|
158
|
+
rescue StandardError
|
159
|
+
::OpenTelemetry::SDK::Resources::Resource.create({})
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.detect_azure
|
163
|
+
attribute = ::OpenTelemetry::Resource::Detector::Azure.detect
|
164
|
+
SolarWindsAPM.logger.debug { "#{self.class}/#{__method__}] retrieved resource_attributes: #{attribute.instance_variable_get(:@attributes)}" }
|
165
|
+
attribute
|
166
|
+
rescue StandardError
|
167
|
+
::OpenTelemetry::SDK::Resources::Resource.create({})
|
168
|
+
end
|
169
|
+
|
170
|
+
def self.detect_container
|
171
|
+
attribute = ::OpenTelemetry::Resource::Detector::Container.detect
|
172
|
+
SolarWindsAPM.logger.debug { "#{self.class}/#{__method__}] retrieved resource_attributes: #{attribute.instance_variable_get(:@attributes)}" }
|
173
|
+
attribute
|
174
|
+
rescue StandardError
|
175
|
+
::OpenTelemetry::SDK::Resources::Resource.create({})
|
176
|
+
end
|
177
|
+
|
178
|
+
def self.safe_integer?(number)
|
179
|
+
min_safe_integer = -((2**53) - 1)
|
180
|
+
max_safe_integer = (2**53) - 1
|
181
|
+
number.is_a?(Integer) && number >= min_safe_integer && number <= max_safe_integer
|
182
|
+
end
|
183
|
+
|
184
|
+
def self.windows?
|
185
|
+
%w[mingw32 cygwin].any? { |platform| RUBY_PLATFORM.include?(platform) }
|
186
|
+
end
|
187
|
+
|
188
|
+
def self.random_uuid
|
189
|
+
SecureRandom.uuid
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -10,19 +10,24 @@ module SolarWindsAPM
|
|
10
10
|
# ServiceKeyChecker
|
11
11
|
# It is a service that validate the service_key
|
12
12
|
class ServiceKeyChecker
|
13
|
+
attr_reader :token, :service_name
|
14
|
+
|
13
15
|
def initialize(reporter, is_lambda)
|
14
16
|
@reporter = reporter
|
15
17
|
@is_lambda = is_lambda
|
18
|
+
@token = nil
|
19
|
+
@service_name = nil
|
20
|
+
read_and_validate_service_key
|
16
21
|
end
|
17
22
|
|
18
23
|
def read_and_validate_service_key
|
19
|
-
return
|
20
|
-
return
|
24
|
+
return unless @reporter == 'ssl'
|
25
|
+
return if @is_lambda
|
21
26
|
|
22
27
|
service_key = fetch_service_key
|
23
28
|
if service_key.empty?
|
24
29
|
SolarWindsAPM.logger.error { "[#{self.class}/#{__method__}] SW_APM_SERVICE_KEY not configured." }
|
25
|
-
return
|
30
|
+
return
|
26
31
|
end
|
27
32
|
|
28
33
|
token, _, service_name = parse_service_key(service_key)
|
@@ -30,7 +35,7 @@ module SolarWindsAPM
|
|
30
35
|
SolarWindsAPM.logger.error do
|
31
36
|
"[#{self.class}/#{__method__}] SW_APM_SERVICE_KEY problem. API Token in wrong format. Masked token: #{token[0..3]}...#{token[-4..]}"
|
32
37
|
end
|
33
|
-
return
|
38
|
+
return
|
34
39
|
end
|
35
40
|
|
36
41
|
# if no service_name from service_key, then the SW_APM_SERVICE_KEY is not right format, return
|
@@ -39,7 +44,7 @@ module SolarWindsAPM
|
|
39
44
|
SolarWindsAPM.logger.warn do
|
40
45
|
"[#{self.class}/#{__method__}] SW_APM_SERVICE_KEY format problem. Service Name is missing."
|
41
46
|
end
|
42
|
-
return
|
47
|
+
return
|
43
48
|
end
|
44
49
|
|
45
50
|
service_name = transform_service_name(service_name)
|
@@ -55,7 +60,8 @@ module SolarWindsAPM
|
|
55
60
|
service_name = transform_service_name(otel_service_name)
|
56
61
|
end
|
57
62
|
|
58
|
-
|
63
|
+
@token = token
|
64
|
+
@service_name = service_name
|
59
65
|
end
|
60
66
|
|
61
67
|
private
|
@@ -28,6 +28,12 @@ module SolarWindsAPM
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
+
# def resolve_config
|
32
|
+
# config = SolarWindsAPM::Config if defined?(SolarWindsAPM::Config)
|
33
|
+
# config = SolarWindsAPM::OTelNativeConfig if defined?(SolarWindsAPM::OTelNativeConfig)
|
34
|
+
# config
|
35
|
+
# end
|
36
|
+
|
31
37
|
def tracing_enabled?
|
32
38
|
span_layer = "#{@kind}:#{@name}"
|
33
39
|
|
@@ -7,32 +7,69 @@
|
|
7
7
|
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
8
8
|
|
9
9
|
module SolarWindsAPM
|
10
|
-
# SolarWindsTxnNameManager
|
11
10
|
# Transaction Name Manager is sole for enabling solarwinds api to call set_transaction_name
|
11
|
+
# 200 unique transaction naming per 60 seconds for the transaction naming
|
12
12
|
class TxnNameManager
|
13
|
+
MAX_CARDINALITY = 200
|
14
|
+
DEFAULT_TXN_NAME = 'other'
|
15
|
+
TXN_NAME_POOL_TTL = 60 # 60s
|
16
|
+
|
17
|
+
# @root_context_h is used for trace api set_transaction_name;
|
18
|
+
# it retrieve the span_id based on root trace_id
|
19
|
+
# set_root_context_h(trace_id, span_flags)
|
20
|
+
# @cache store the transaction name that will be used for exporter
|
21
|
+
# to set transaction name for attributes, get by trace_span_id
|
22
|
+
# set(trace_span_id, transaction_name)
|
23
|
+
# @transaction_name store the transaction name and its expire call
|
24
|
+
# set(transaction_name, thread {@cache.del()})
|
13
25
|
def initialize
|
14
|
-
@cache = {}
|
15
|
-
@
|
26
|
+
@cache = {} # for mapping trace_span_id to transaction name
|
27
|
+
@transaction_name = {} # only make sure the cardinality requirement that 200 unique txn within 60s
|
28
|
+
# use for setting DEFAULT_TXN_NAME (in @cache) when cardinality reach the maximal
|
29
|
+
@root_context_h = {} # for set_transaction_name api call
|
16
30
|
@mutex = Mutex.new
|
31
|
+
@root_context_mutex = Mutex.new
|
17
32
|
end
|
18
33
|
|
19
34
|
def get(key)
|
20
|
-
@cache[key]
|
35
|
+
@mutex.synchronize { @cache[key] }
|
21
36
|
end
|
22
37
|
|
23
38
|
def del(key)
|
24
|
-
@cache.delete(key)
|
39
|
+
@mutex.synchronize { @cache.delete(key) }
|
25
40
|
end
|
26
41
|
|
27
42
|
def set(key, value)
|
28
|
-
|
43
|
+
# new name and room in pool -> add name to pool and schedule for removal after ttl -> return name
|
44
|
+
# new name but no room in pool -> return default name
|
45
|
+
# existing name -> cancel previously scheduled removal -> schedule new removal -> return name
|
46
|
+
txn_name = value.slice(0, SolarWindsAPM::Constants::MAX_TXN_NAME_LENGTH)
|
47
|
+
txn_name_exist = false
|
48
|
+
|
49
|
+
# thread exit execute ensure block, better option than kill for sleep
|
50
|
+
@mutex.synchronize do
|
51
|
+
if @transaction_name[txn_name]
|
52
|
+
txn_name_exist = true
|
53
|
+
@transaction_name[txn_name].exit
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
@mutex.synchronize do
|
58
|
+
if txn_name_exist || @transaction_name.size < MAX_CARDINALITY
|
59
|
+
@cache[key] = txn_name
|
60
|
+
@transaction_name[txn_name] = Thread.new { cleanup_txn(key, txn_name) }
|
61
|
+
else
|
62
|
+
@cache[key] = DEFAULT_TXN_NAME
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
29
66
|
SolarWindsAPM.logger.debug { "[#{self.class}/#{__method__}] txn manager current cache #{@cache.inspect}" }
|
30
67
|
end
|
31
68
|
|
32
69
|
alias []= set
|
33
70
|
|
34
71
|
def set_root_context_h(key, value)
|
35
|
-
@
|
72
|
+
@root_context_mutex.synchronize do
|
36
73
|
@root_context_h[key] = value
|
37
74
|
end
|
38
75
|
SolarWindsAPM.logger.debug do
|
@@ -41,13 +78,21 @@ module SolarWindsAPM
|
|
41
78
|
end
|
42
79
|
|
43
80
|
def get_root_context_h(key)
|
44
|
-
@root_context_h[key]
|
81
|
+
@root_context_mutex.synchronize { @root_context_h[key] }
|
45
82
|
end
|
46
83
|
|
47
84
|
def delete_root_context_h(key)
|
48
|
-
@
|
85
|
+
@root_context_mutex.synchronize do
|
49
86
|
@root_context_h.delete(key)
|
50
87
|
end
|
51
88
|
end
|
89
|
+
|
90
|
+
def cleanup_txn(_key, txn_name)
|
91
|
+
sleep(TXN_NAME_POOL_TTL)
|
92
|
+
ensure
|
93
|
+
@mutex.synchronize do
|
94
|
+
@transaction_name.delete(txn_name)
|
95
|
+
end
|
96
|
+
end
|
52
97
|
end
|
53
98
|
end
|
@@ -29,5 +29,14 @@ module SolarWindsAPM
|
|
29
29
|
end
|
30
30
|
xtr
|
31
31
|
end
|
32
|
+
|
33
|
+
def self.determine_lambda
|
34
|
+
if ENV['LAMBDA_TASK_ROOT'].to_s.empty? && ENV['AWS_LAMBDA_FUNCTION_NAME'].to_s.empty?
|
35
|
+
false
|
36
|
+
else
|
37
|
+
SolarWindsAPM.logger.debug { "[#{self.class}/#{__method__}] lambda environment - LAMBDA_TASK_ROOT: #{ENV.fetch('LAMBDA_TASK_ROOT', nil)}; AWS_LAMBDA_FUNCTION_NAME: #{ENV.fetch('AWS_LAMBDA_FUNCTION_NAME', nil)}" }
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
32
41
|
end
|
33
42
|
end
|
@@ -11,10 +11,9 @@
|
|
11
11
|
require_relative 'support/logger_formatter'
|
12
12
|
require_relative 'support/logging_log_event'
|
13
13
|
require_relative 'support/lumberjack_formatter'
|
14
|
-
require_relative 'support/transaction_cache'
|
15
14
|
require_relative 'support/transaction_settings'
|
16
|
-
require_relative 'support/oboe_tracing_mode'
|
17
15
|
require_relative 'support/txn_name_manager'
|
18
16
|
require_relative 'support/utils'
|
19
|
-
require_relative 'support/
|
20
|
-
require_relative 'support/
|
17
|
+
require_relative 'support/otlp_endpoint'
|
18
|
+
require_relative 'support/resource_detector'
|
19
|
+
require_relative 'support/aws_resource_detector'
|
@@ -11,10 +11,10 @@ module SolarWindsAPM
|
|
11
11
|
# The current version of the gem. Used mainly by
|
12
12
|
# solarwinds_apm.gemspec during gem build process
|
13
13
|
module Version
|
14
|
-
MAJOR =
|
15
|
-
MINOR =
|
16
|
-
PATCH =
|
17
|
-
PRE =
|
14
|
+
MAJOR = 7 # breaking,
|
15
|
+
MINOR = 0 # feature,
|
16
|
+
PATCH = 0 # fix => BFF
|
17
|
+
PRE = 'prev1'
|
18
18
|
|
19
19
|
STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
20
20
|
end
|