Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/release-notification-on-slack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
- name: 'Checkout'
uses: actions/checkout@v3
- run: |
if [[ ${{ github.event_name == 'workflow_dispatch' }} == true ]]; then
export GITHUB_RELEASE_TAG=${{ inputs.github_ref }}
if [[ "${EVENT_NAME}" == "workflow_dispatch" ]]; then
export GITHUB_RELEASE_TAG="${INPUT_GITHUB_REF}"
else # release event
export GITHUB_RELEASE_TAG=$(basename ${GITHUB_REF})
fi
Expand All @@ -29,6 +29,8 @@ jobs:
ls -lah
python ./.github/scripts/announce_release_on_slack.py
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_GITHUB_REF: ${{ inputs.github_ref }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_TOKEN: ${{ secrets.RUPY_TRACER_RELEASES_TOKEN }}
SLACK_SERVICE: ${{ secrets.RUPY_TRACER_RELEASES_SERVICE_ID }}
Expand Down
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ Style/SymbolProc:
Enabled: false

Style/MultilineBlockChain:
Enabled: false
Enabled: false

# Allow an explicit `else nil` in case statements (SonarCloud S131 requires a default clause)
Style/EmptyElse:
EnforcedStyle: empty
2 changes: 1 addition & 1 deletion lib/instana/backend/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Backend
class Agent
attr_reader :delegate

def initialize(fargate_metadata_uri: ENV['ECS_CONTAINER_METADATA_URI'], logger: ::Instana.logger)
def initialize(fargate_metadata_uri: ENV.fetch('ECS_CONTAINER_METADATA_URI', nil), logger: ::Instana.logger)
@delegate = nil
@logger = logger
@fargate_metadata_uri = fargate_metadata_uri
Expand Down
4 changes: 3 additions & 1 deletion lib/instana/backend/host_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def initialize(discovery: Concurrent::Atom.new(nil), logger: ::Instana.logger)
@agent_connection_task = Concurrent::TimerTask.new(execution_interval: 75) { announce }
end

def setup; end
def setup
# No setup needed: the host agent is activated via the announce timer task
end

def spawn_background_thread
return if ENV.key?('INSTANA_TEST')
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/backend/process_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def clean_arguments(arguments)
arguments.reject do |a|
if a.include?('=')
k, = a.split('=', 2)
ENV[k]
ENV.fetch(k, nil)
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions lib/instana/backend/serverless_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(snapshots,
timer_class: Concurrent::TimerTask,
processor: ::Instana.processor,
logger: ::Instana.logger,
backend_uri: ENV['INSTANA_ENDPOINT_URL'],
backend_uri: ENV.fetch('INSTANA_ENDPOINT_URL', nil),
secrets: ENV.fetch('INSTANA_SECRETS', DEFAULT_SECRETS), headers: ENV.fetch('INSTANA_EXTRA_HTTP_HEADERS', ''))
@snapshots = snapshots
@processor = processor
Expand All @@ -26,7 +26,9 @@ def initialize(snapshots,
end
# rubocop:enable Metrics/ParameterLists

def setup; end
def setup
# No setup needed: the serverless agent is ready on construction
end

def spawn_background_thread
@timer.execute
Expand Down Expand Up @@ -85,7 +87,7 @@ def send_bundle
def request_headers
{
'X-Instana-Host' => host_name,
'X-Instana-Key' => ENV['INSTANA_AGENT_KEY'],
'X-Instana-Key' => ENV.fetch('INSTANA_AGENT_KEY', nil),
'X-Instana-Time' => (Time.now.to_i * 1000).to_s
}
end
Expand Down
7 changes: 4 additions & 3 deletions lib/instana/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Config # rubocop:disable Metrics/ClassLength

LEGACY_TRACING_KEY = 'com.instana.tracing'.freeze
TRACING_KEY = 'tracing'.freeze
DISABLE_SERVER_TIMING_KEY = 'disable-server-timing'.freeze

def initialize(logger: ::Instana.logger, agent_host: ENV.fetch('INSTANA_AGENT_HOST', nil), agent_port: ENV.fetch('INSTANA_AGENT_PORT', nil)) # rubocop:disable Metrics/MethodLength
@config = {}
Expand Down Expand Up @@ -302,7 +303,7 @@ def parse_disable_server_timing_from_yaml
yaml_content = YAML.safe_load(File.read(config_path))
tracing_config = yaml_content[TRACING_KEY] || yaml_content[LEGACY_TRACING_KEY]
global_config = tracing_config && tracing_config['global']
global_config.is_a?(Hash) ? global_config['disable-server-timing'] : nil
global_config.is_a?(Hash) ? global_config[DISABLE_SERVER_TIMING_KEY] : nil
rescue => e
::Instana.logger.warn("Failed to load disable-server-timing configuration from YAML: #{e.message}")
nil
Expand All @@ -311,9 +312,9 @@ def parse_disable_server_timing_from_yaml
# @param tracing_config [Hash] the tracing sub-hash from the discovery payload
def read_disable_server_timing_from_agent(tracing_config)
global_config = tracing_config['global']
return unless global_config.is_a?(Hash) && !global_config['disable-server-timing'].nil?
return unless global_config.is_a?(Hash) && !global_config[DISABLE_SERVER_TIMING_KEY].nil?

@config[:disable_server_timing] = truthy?(global_config['disable-server-timing'])
@config[:disable_server_timing] = truthy?(global_config[DISABLE_SERVER_TIMING_KEY])
@config[:disable_server_timing_source] = 'agent'
end

Expand Down
2 changes: 2 additions & 0 deletions lib/instana/instrumentation/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def describe_direct(options)
options[:template]
when ->(o) { o.key?(:file) }
options[:file]
else
nil # unrecognized render option
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/instana/instrumentation/aws_sdk_sqs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def call(context)
inject_instana_headers(span, context.params)
when :send_message_batch
context.params[:entries].each { |e| inject_instana_headers(span, e) }
else
nil # other operations carry no message attributes to inject
end

response = @handler.call(context)
Expand Down
8 changes: 5 additions & 3 deletions lib/instana/instrumentation/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
module Instana
module Instrumentation
class GraphqlTracing < GraphQL::Tracing::PlatformTracing
EXECUTE_GRAPHQL = 'execute.graphql'.freeze

self.platform_keys = {
'lex' => 'lex.graphql',
'parse' => 'parse.graphql',
'validate' => 'validate.graphql',
'analyze_query' => 'analyze.graphql',
'analyze_multiplex' => 'analyze.graphql',
'execute_multiplex' => 'execute.graphql',
'execute_query' => 'execute.graphql',
'execute_query_lazy' => 'execute.graphql',
'execute_multiplex' => EXECUTE_GRAPHQL,
'execute_query' => EXECUTE_GRAPHQL,
'execute_query_lazy' => EXECUTE_GRAPHQL,
}

def platform_trace(platform_key, key, data)
Expand Down
13 changes: 8 additions & 5 deletions lib/instana/instrumentation/grpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

module Instana
module Instrumentation
INSTANA_TRACE_ID_METADATA_KEY = 'x-instana-t'.freeze
INSTANA_SPAN_ID_METADATA_KEY = 'x-instana-s'.freeze

module GRPCCientInstrumentation
CALL_TYPES = [:request_response, :client_streamer, :server_streamer, :bidi_streamer]

Expand All @@ -27,8 +30,8 @@ module GRPCCientInstrumentation
context = ::Instana.tracer.context
if context
extra = {
'x-instana-t' => context.trace_id_header,
'x-instana-s' => context.span_id_header,
INSTANA_TRACE_ID_METADATA_KEY => context.trace_id_header,
INSTANA_SPAN_ID_METADATA_KEY => context.span_id_header,
'x-instana-l' => context.level.to_s,
'traceparent' => context.trace_parent_header,
'tracestate' => context.trace_state_header
Expand Down Expand Up @@ -91,7 +94,7 @@ module GRPCServerInstrumentation
private

def extract_grpc_context(metadata)
if metadata.key?('x-instana-t')
if metadata.key?(INSTANA_TRACE_ID_METADATA_KEY)
extract_instana_grpc_context(metadata)
elsif metadata.key?('traceparent')
extract_w3c_grpc_context(metadata)
Expand All @@ -100,8 +103,8 @@ def extract_grpc_context(metadata)

def extract_instana_grpc_context(metadata)
SpanContext.new(
trace_id: ::Instana::Util.header_to_id(metadata['x-instana-t']),
span_id: metadata.key?('x-instana-s') ? ::Instana::Util.header_to_id(metadata['x-instana-s']) : nil,
trace_id: ::Instana::Util.header_to_id(metadata[INSTANA_TRACE_ID_METADATA_KEY]),
span_id: metadata.key?(INSTANA_SPAN_ID_METADATA_KEY) ? ::Instana::Util.header_to_id(metadata[INSTANA_SPAN_ID_METADATA_KEY]) : nil,
level: metadata['x-instana-l'] || 1
)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/instana/serverless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(agent: ::Instana.agent, tracer: ::Instana.tracer, logger: ::Insta
end

def wrap_aws(event, context, &block)
Thread.current[:instana_function_arn] = [context.invoked_function_arn, context.function_version].join(':')
Fiber[:instana_function_arn] = [context.invoked_function_arn, context.function_version].join(':')
trigger, event_tags, span_context = trigger_from_event(event, context)

tags = {
Expand Down Expand Up @@ -52,7 +52,7 @@ def wrap_aws(event, context, &block)
rescue StandardError => e
@logger.error(e.message)
end
Thread.current[:instana_function_arn] = nil
Fiber[:instana_function_arn] = nil
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/snapshot/docker_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DockerContainer
include Deltable
ID = 'com.instana.plugin.docker'.freeze

def initialize(container, metadata_uri: ENV['ECS_CONTAINER_METADATA_URI'])
def initialize(container, metadata_uri: ENV.fetch('ECS_CONTAINER_METADATA_URI', nil))
@container = container
@metadata_uri = URI(metadata_uri)
@client = Backend::RequestClient.new(@metadata_uri.host, @metadata_uri.port, use_ssl: @metadata_uri.scheme == "https")
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/snapshot/fargate_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Snapshot
class FargateContainer
ID = 'com.instana.plugin.aws.ecs.container'.freeze

def initialize(container, metadata_uri: ENV['ECS_CONTAINER_METADATA_URI'])
def initialize(container, metadata_uri: ENV.fetch('ECS_CONTAINER_METADATA_URI', nil))
@container = container
@metadata_uri = URI(metadata_uri)
@client = Backend::RequestClient.new(@metadata_uri.host, @metadata_uri.port, use_ssl: @metadata_uri.scheme == "https")
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/snapshot/fargate_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Snapshot
class FargateProcess
ID = 'com.instana.plugin.process'.freeze

def initialize(metadata_uri: ENV['ECS_CONTAINER_METADATA_URI'])
def initialize(metadata_uri: ENV.fetch('ECS_CONTAINER_METADATA_URI', nil))
@metadata_uri = URI(metadata_uri)
@client = Backend::RequestClient.new(@metadata_uri.host, @metadata_uri.port, use_ssl: @metadata_uri.scheme == "https")
@start_time = Time.now
Expand Down
4 changes: 2 additions & 2 deletions lib/instana/snapshot/fargate_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Snapshot
class FargateTask
ID = 'com.instana.plugin.aws.ecs.task'.freeze

def initialize(metadata_uri: ENV['ECS_CONTAINER_METADATA_URI'])
def initialize(metadata_uri: ENV.fetch('ECS_CONTAINER_METADATA_URI', nil))
@metadata_uri = URI(metadata_uri)
@client = Backend::RequestClient.new(@metadata_uri.host, @metadata_uri.port, use_ssl: @metadata_uri.scheme == "https")
end
Expand Down Expand Up @@ -49,7 +49,7 @@ def task_metadata
end

def instana_zone
ENV['INSTANA_ZONE']
ENV.fetch('INSTANA_ZONE', nil)
end

def instana_tags
Expand Down
10 changes: 5 additions & 5 deletions lib/instana/snapshot/google_cloud_run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def data
{
runtime: 'ruby',
region: gcp_region,
service: ENV['K_SERVICE'],
configuration: ENV['K_CONFIGURATION'],
revision: ENV['K_REVISION'],
service: ENV.fetch('K_SERVICE', nil),
configuration: ENV.fetch('K_CONFIGURATION', nil),
revision: ENV.fetch('K_REVISION', nil),
instanceId: entity_id,
port: ENV['PORT'],
port: ENV.fetch('PORT', nil),
numericProjectId: lookup('/computeMetadata/v1/project/numeric-project-id'),
projectId: lookup('/computeMetadata/v1/project/project-id')
}.reject { |_, v| v.nil? }
Expand All @@ -47,7 +47,7 @@ def source
end

def host_name
"gcp:cloud-run:revision:#{ENV['K_REVISION']}"
"gcp:cloud-run:revision:#{ENV.fetch('K_REVISION', nil)}"
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/snapshot/google_cloud_run_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def data
start: @start_time.to_i * 1000,
containerType: 'gcpCloudRunInstance',
container: lookup('/computeMetadata/v1/instance/id'),
"com.instana.plugin.host.name": "gcp:cloud-run:revision:#{ENV['K_REVISION']}"
"com.instana.plugin.host.name": "gcp:cloud-run:revision:#{ENV.fetch('K_REVISION', nil)}"
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/instana/snapshot/lambda_function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class LambdaFunction
ID = "com.instana.plugin.aws.lambda".freeze

def entity_id
Thread.current[:instana_function_arn]
Fiber[:instana_function_arn]
end

def data
Expand Down
8 changes: 5 additions & 3 deletions lib/instana/span_filtering/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def rules_loaded?

# Load configuration from YAML file specified by INSTANA_CONFIG_PATH
def load_from_yaml
config_path = ENV['INSTANA_CONFIG_PATH']
config_path = ENV.fetch('INSTANA_CONFIG_PATH', nil)
return unless config_path && File.exist?(config_path)

begin
Expand Down Expand Up @@ -130,9 +130,9 @@ def load_from_env_vars
end
end

return unless !ENV["INSTANA_TRACING_DISABLE"].nil? && !%w[True true 1].include?(ENV["INSTANA_TRACING_DISABLE"])
return unless !ENV.fetch("INSTANA_TRACING_DISABLE", nil).nil? && !%w[True true 1].include?(ENV.fetch("INSTANA_TRACING_DISABLE", nil))

process_disable_config(ENV["INSTANA_TRACING_DISABLE"].split(','))
process_disable_config(ENV.fetch("INSTANA_TRACING_DISABLE").split(','))
end

# Process rules from YAML configuration
Expand Down Expand Up @@ -219,6 +219,8 @@ def update_instana_config_for_disabled_technology(technology)
when :databases
# If databases category is disabled, also disable redis
::Instana.config[:redis][:enabled] = false
else
nil # no Instana::Config toggle exists for other technologies
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/instana/trace.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# (c) Copyright IBM Corp. 2025
require 'opentelemetry/context'
require 'instana/trace/span_context'
require 'instana/trace/span_kind'
require 'instana/trace/span'
require 'instana/trace/tracer'

module Instana
# The Trace API allows recording a set of events, triggered as a result of a
# single logical operation, consolidated across various components of an
Expand Down Expand Up @@ -67,8 +72,3 @@ def non_recording_span(span_context)
end
end
end

require 'instana/trace/span_context'
require 'instana/trace/span_kind'
require 'instana/trace/span'
require 'instana/trace/tracer'
4 changes: 3 additions & 1 deletion lib/instana/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@ def add_event(_name, attributes: nil, timestamp: nil) # rubocop:disable Lint/Unu
# status, which is OK.
#
# @return [void]
def status=(status); end
def status=(status)
# Intentionally a no-op: Instana spans do not track an OTel status
end

def should_collect_stack_trace?
return false unless exit_span?
Expand Down
5 changes: 3 additions & 2 deletions lib/instana/util.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2016

require 'net/http'

module Instana
module Util # rubocop:disable Metrics/ModuleLength
class << self
Expand Down Expand Up @@ -71,7 +73,7 @@ def take_snapshot
# :nocov:
def get_app_name
if ENV.key?('INSTANA_SERVICE_NAME')
return ENV['INSTANA_SERVICE_NAME']
return ENV.fetch('INSTANA_SERVICE_NAME')
end

if defined?(::Resque)
Expand Down Expand Up @@ -261,7 +263,6 @@ def should_mark_http_exit_as_error?(status_code)
# Uses Ruby stdlib Net::HTTPResponse::CODE_TO_OBJ to derive the phrase from
# the response class name (e.g. Net::HTTPUnauthorized → "Unauthorized").
def http_reason_phrase(status_code)
require 'net/http'
klass = Net::HTTPResponse::CODE_TO_OBJ[status_code.to_s]
return nil unless klass

Expand Down
Loading
Loading