skywalking 0.0.0.alpha
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 +7 -0
- data/.asf.yaml +40 -0
- data/.rspec +3 -0
- data/.rubocop.yml +236 -0
- data/CHANGELOG.md +15 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE +201 -0
- data/NOTICE +5 -0
- data/README.md +18 -0
- data/Rakefile +23 -0
- data/docs/How-to-release.md +179 -0
- data/examples/rails-demo/.dockerignore +47 -0
- data/examples/rails-demo/.gitattributes +9 -0
- data/examples/rails-demo/.gitignore +34 -0
- data/examples/rails-demo/.kamal/hooks/docker-setup.sample +3 -0
- data/examples/rails-demo/.kamal/hooks/post-deploy.sample +14 -0
- data/examples/rails-demo/.kamal/hooks/post-proxy-reboot.sample +3 -0
- data/examples/rails-demo/.kamal/hooks/pre-build.sample +51 -0
- data/examples/rails-demo/.kamal/hooks/pre-connect.sample +47 -0
- data/examples/rails-demo/.kamal/hooks/pre-deploy.sample +109 -0
- data/examples/rails-demo/.kamal/hooks/pre-proxy-reboot.sample +3 -0
- data/examples/rails-demo/.kamal/secrets +17 -0
- data/examples/rails-demo/.rubocop.yml +8 -0
- data/examples/rails-demo/.ruby-version +1 -0
- data/examples/rails-demo/Dockerfile +72 -0
- data/examples/rails-demo/Gemfile +64 -0
- data/examples/rails-demo/README.md +24 -0
- data/examples/rails-demo/Rakefile +6 -0
- data/examples/rails-demo/app/assets/images/.keep +0 -0
- data/examples/rails-demo/app/assets/stylesheets/application.css +10 -0
- data/examples/rails-demo/app/controllers/application_controller.rb +4 -0
- data/examples/rails-demo/app/controllers/concerns/.keep +0 -0
- data/examples/rails-demo/app/helpers/application_helper.rb +2 -0
- data/examples/rails-demo/app/javascript/application.js +3 -0
- data/examples/rails-demo/app/javascript/controllers/application.js +9 -0
- data/examples/rails-demo/app/javascript/controllers/hello_controller.js +7 -0
- data/examples/rails-demo/app/javascript/controllers/index.js +4 -0
- data/examples/rails-demo/app/jobs/application_job.rb +7 -0
- data/examples/rails-demo/app/mailers/application_mailer.rb +4 -0
- data/examples/rails-demo/app/models/application_record.rb +3 -0
- data/examples/rails-demo/app/models/concerns/.keep +0 -0
- data/examples/rails-demo/app/views/layouts/application.html.erb +28 -0
- data/examples/rails-demo/app/views/layouts/mailer.html.erb +13 -0
- data/examples/rails-demo/app/views/layouts/mailer.text.erb +1 -0
- data/examples/rails-demo/app/views/pwa/manifest.json.erb +22 -0
- data/examples/rails-demo/app/views/pwa/service-worker.js +26 -0
- data/examples/rails-demo/bin/brakeman +7 -0
- data/examples/rails-demo/bin/bundle +109 -0
- data/examples/rails-demo/bin/dev +2 -0
- data/examples/rails-demo/bin/docker-entrypoint +14 -0
- data/examples/rails-demo/bin/importmap +4 -0
- data/examples/rails-demo/bin/jobs +6 -0
- data/examples/rails-demo/bin/kamal +27 -0
- data/examples/rails-demo/bin/rails +4 -0
- data/examples/rails-demo/bin/rake +4 -0
- data/examples/rails-demo/bin/rubocop +8 -0
- data/examples/rails-demo/bin/setup +34 -0
- data/examples/rails-demo/bin/thrust +5 -0
- data/examples/rails-demo/config/application.rb +27 -0
- data/examples/rails-demo/config/boot.rb +4 -0
- data/examples/rails-demo/config/cable.yml +17 -0
- data/examples/rails-demo/config/cache.yml +16 -0
- data/examples/rails-demo/config/credentials.yml.enc +1 -0
- data/examples/rails-demo/config/database.yml +41 -0
- data/examples/rails-demo/config/deploy.yml +116 -0
- data/examples/rails-demo/config/environment.rb +5 -0
- data/examples/rails-demo/config/environments/development.rb +72 -0
- data/examples/rails-demo/config/environments/production.rb +90 -0
- data/examples/rails-demo/config/environments/test.rb +53 -0
- data/examples/rails-demo/config/importmap.rb +7 -0
- data/examples/rails-demo/config/initializers/assets.rb +7 -0
- data/examples/rails-demo/config/initializers/content_security_policy.rb +25 -0
- data/examples/rails-demo/config/initializers/filter_parameter_logging.rb +8 -0
- data/examples/rails-demo/config/initializers/inflections.rb +16 -0
- data/examples/rails-demo/config/initializers/skywalking_ruby.rb +18 -0
- data/examples/rails-demo/config/locales/en.yml +31 -0
- data/examples/rails-demo/config/puma.rb +41 -0
- data/examples/rails-demo/config/queue.yml +18 -0
- data/examples/rails-demo/config/recurring.yml +10 -0
- data/examples/rails-demo/config/routes.rb +14 -0
- data/examples/rails-demo/config/storage.yml +34 -0
- data/examples/rails-demo/config.ru +6 -0
- data/examples/rails-demo/db/cable_schema.rb +11 -0
- data/examples/rails-demo/db/cache_schema.rb +14 -0
- data/examples/rails-demo/db/queue_schema.rb +129 -0
- data/examples/rails-demo/db/seeds.rb +9 -0
- data/examples/rails-demo/lib/tasks/.keep +0 -0
- data/examples/rails-demo/log/.keep +0 -0
- data/examples/rails-demo/public/400.html +114 -0
- data/examples/rails-demo/public/404.html +114 -0
- data/examples/rails-demo/public/406-unsupported-browser.html +114 -0
- data/examples/rails-demo/public/422.html +114 -0
- data/examples/rails-demo/public/500.html +114 -0
- data/examples/rails-demo/public/icon.png +0 -0
- data/examples/rails-demo/public/icon.svg +3 -0
- data/examples/rails-demo/public/robots.txt +1 -0
- data/examples/rails-demo/script/.keep +0 -0
- data/examples/rails-demo/storage/.keep +0 -0
- data/examples/rails-demo/test/application_system_test_case.rb +5 -0
- data/examples/rails-demo/test/controllers/.keep +0 -0
- data/examples/rails-demo/test/fixtures/files/.keep +0 -0
- data/examples/rails-demo/test/helpers/.keep +0 -0
- data/examples/rails-demo/test/integration/.keep +0 -0
- data/examples/rails-demo/test/mailers/.keep +0 -0
- data/examples/rails-demo/test/models/.keep +0 -0
- data/examples/rails-demo/test/system/.keep +0 -0
- data/examples/rails-demo/test/test_helper.rb +15 -0
- data/examples/rails-demo/tmp/.keep +0 -0
- data/examples/rails-demo/tmp/pids/.keep +0 -0
- data/examples/rails-demo/tmp/storage/.keep +0 -0
- data/examples/rails-demo/vendor/.keep +0 -0
- data/examples/rails-demo/vendor/javascript/.keep +0 -0
- data/examples/sinatra-demo/sinatra-demo.rb +32 -0
- data/lib/skywalking/agent.rb +98 -0
- data/lib/skywalking/configuration.rb +255 -0
- data/lib/skywalking/environment.rb +50 -0
- data/lib/skywalking/log/logger.rb +53 -0
- data/lib/skywalking/plugins/redis5.rb +70 -0
- data/lib/skywalking/plugins/sinatra.rb +55 -0
- data/lib/skywalking/plugins_manager.rb +84 -0
- data/lib/skywalking/proto/asyncprofiler/AsyncProfiler_pb.rb +23 -0
- data/lib/skywalking/proto/asyncprofiler/AsyncProfiler_services_pb.rb +45 -0
- data/lib/skywalking/proto/browser/BrowserPerfCompat_pb.rb +15 -0
- data/lib/skywalking/proto/browser/BrowserPerfCompat_services_pb.rb +42 -0
- data/lib/skywalking/proto/browser/BrowserPerf_pb.rb +21 -0
- data/lib/skywalking/proto/browser/BrowserPerf_services_pb.rb +46 -0
- data/lib/skywalking/proto/common/Command_pb.rb +20 -0
- data/lib/skywalking/proto/common/Common_pb.rb +21 -0
- data/lib/skywalking/proto/ebpf/accesslog_pb.rb +58 -0
- data/lib/skywalking/proto/ebpf/accesslog_services_pb.rb +42 -0
- data/lib/skywalking/proto/event/Event_pb.rb +21 -0
- data/lib/skywalking/proto/event/Event_services_pb.rb +45 -0
- data/lib/skywalking/proto/language-agent/CLRMetricCompat_pb.rb +15 -0
- data/lib/skywalking/proto/language-agent/CLRMetricCompat_services_pb.rb +38 -0
- data/lib/skywalking/proto/language-agent/CLRMetric_pb.rb +23 -0
- data/lib/skywalking/proto/language-agent/CLRMetric_services_pb.rb +42 -0
- data/lib/skywalking/proto/language-agent/ConfigurationDiscoveryService_pb.rb +19 -0
- data/lib/skywalking/proto/language-agent/ConfigurationDiscoveryService_services_pb.rb +51 -0
- data/lib/skywalking/proto/language-agent/JVMMetricCompat_pb.rb +15 -0
- data/lib/skywalking/proto/language-agent/JVMMetricCompat_services_pb.rb +39 -0
- data/lib/skywalking/proto/language-agent/JVMMetric_pb.rb +28 -0
- data/lib/skywalking/proto/language-agent/JVMMetric_services_pb.rb +43 -0
- data/lib/skywalking/proto/language-agent/MeterCompat_pb.rb +15 -0
- data/lib/skywalking/proto/language-agent/MeterCompat_services_pb.rb +39 -0
- data/lib/skywalking/proto/language-agent/Meter_pb.rb +24 -0
- data/lib/skywalking/proto/language-agent/Meter_services_pb.rb +48 -0
- data/lib/skywalking/proto/language-agent/TracingCompat_pb.rb +15 -0
- data/lib/skywalking/proto/language-agent/TracingCompat_services_pb.rb +48 -0
- data/lib/skywalking/proto/language-agent/Tracing_pb.rb +31 -0
- data/lib/skywalking/proto/language-agent/Tracing_services_pb.rb +71 -0
- data/lib/skywalking/proto/logging/Logging_pb.rb +26 -0
- data/lib/skywalking/proto/logging/Logging_services_pb.rb +46 -0
- data/lib/skywalking/proto/management/ManagementCompat_pb.rb +15 -0
- data/lib/skywalking/proto/management/ManagementCompat_services_pb.rb +44 -0
- data/lib/skywalking/proto/management/Management_pb.rb +21 -0
- data/lib/skywalking/proto/management/Management_services_pb.rb +48 -0
- data/lib/skywalking/proto/profile/ProfileCompat_pb.rb +15 -0
- data/lib/skywalking/proto/profile/ProfileCompat_services_pb.rb +43 -0
- data/lib/skywalking/proto/profile/Profile_pb.rb +22 -0
- data/lib/skywalking/proto/profile/Profile_services_pb.rb +47 -0
- data/lib/skywalking/proto/service-mesh-probe/service-mesh_pb.rb +25 -0
- data/lib/skywalking/proto/service-mesh-probe/service-mesh_services_pb.rb +43 -0
- data/lib/skywalking/reporter/buffer_trigger.rb +108 -0
- data/lib/skywalking/reporter/client/grpc_client.rb +114 -0
- data/lib/skywalking/reporter/client/proto.rb +29 -0
- data/lib/skywalking/reporter/grpc.rb +46 -0
- data/lib/skywalking/reporter/protocol.rb +28 -0
- data/lib/skywalking/reporter/report.rb +82 -0
- data/lib/skywalking/reporter/scheduler.rb +158 -0
- data/lib/skywalking/tracing/carrier.rb +121 -0
- data/lib/skywalking/tracing/carrier_item.rb +27 -0
- data/lib/skywalking/tracing/constants.rb +49 -0
- data/lib/skywalking/tracing/entry_span.rb +48 -0
- data/lib/skywalking/tracing/exit_span.rb +53 -0
- data/lib/skywalking/tracing/ignored_context.rb +34 -0
- data/lib/skywalking/tracing/noop_span.rb +32 -0
- data/lib/skywalking/tracing/segment.rb +57 -0
- data/lib/skywalking/tracing/span.rb +111 -0
- data/lib/skywalking/tracing/span_context.rb +242 -0
- data/lib/skywalking/tracing/tag.rb +49 -0
- data/lib/skywalking/utils/id_gen.rb +30 -0
- data/lib/skywalking/version.rb +18 -0
- data/lib/skywalking.rb +36 -0
- metadata +340 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright ownership.
|
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
|
6
|
+
# the License. You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require_relative '../utils/id_gen'
|
|
17
|
+
|
|
18
|
+
module Skywalking
|
|
19
|
+
module Tracing
|
|
20
|
+
class Segment
|
|
21
|
+
attr_accessor :segment_id, :spans, :timestamp, :related_traces
|
|
22
|
+
|
|
23
|
+
def initialize
|
|
24
|
+
@segment_id = Utils::IDGen.new
|
|
25
|
+
@spans = []
|
|
26
|
+
@timestamp = (Process.clock_gettime(Process::CLOCK_REALTIME) * 1000).to_i
|
|
27
|
+
@related_traces = [Utils::IDGen.new]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def archive(span)
|
|
31
|
+
@spans << span
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def relate(trace_id)
|
|
35
|
+
@related_traces.shift if @related_traces.first.is_a?(Utils::IDGen.new)
|
|
36
|
+
@related_traces << trace_id
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class SegmentRef
|
|
41
|
+
attr_reader :trace_id, :ref_type, :segment_id,
|
|
42
|
+
:span_id, :service, :service_instance,
|
|
43
|
+
:endpoint, :peer
|
|
44
|
+
|
|
45
|
+
def initialize(carrier, ref_type: 'CrossProcess')
|
|
46
|
+
@ref_type = ref_type
|
|
47
|
+
@trace_id = carrier.trace_id
|
|
48
|
+
@segment_id = carrier.segment_id
|
|
49
|
+
@span_id = carrier.span_id.to_i
|
|
50
|
+
@service = carrier.service
|
|
51
|
+
@service_instance = carrier.service_instance
|
|
52
|
+
@endpoint = carrier.endpoint
|
|
53
|
+
@peer = carrier.peer
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright ownership.
|
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
|
6
|
+
# the License. You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require_relative 'constants'
|
|
17
|
+
require_relative 'carrier'
|
|
18
|
+
require_relative '../reporter/client/proto'
|
|
19
|
+
|
|
20
|
+
module Skywalking
|
|
21
|
+
module Tracing
|
|
22
|
+
class Span
|
|
23
|
+
attr_accessor :operation, :inherit, :component,
|
|
24
|
+
:context, :tags, :peer, :layer
|
|
25
|
+
|
|
26
|
+
attr_reader :stack_depth, :kind, :parent_id,
|
|
27
|
+
:start_time, :end_time, :span_id, :refs
|
|
28
|
+
|
|
29
|
+
def initialize(
|
|
30
|
+
context:,
|
|
31
|
+
span_id: -1,
|
|
32
|
+
parent_id: -1,
|
|
33
|
+
operation: nil,
|
|
34
|
+
peer: nil,
|
|
35
|
+
kind: nil,
|
|
36
|
+
component: nil,
|
|
37
|
+
layer: nil
|
|
38
|
+
)
|
|
39
|
+
@context = context
|
|
40
|
+
@operation = operation
|
|
41
|
+
@span_id = span_id
|
|
42
|
+
@parent_id = parent_id
|
|
43
|
+
@peer = peer
|
|
44
|
+
@layer = layer || Layer::Unknown
|
|
45
|
+
@kind = kind || nil
|
|
46
|
+
@component = component || Component::Unknown
|
|
47
|
+
|
|
48
|
+
@stack_depth = 0
|
|
49
|
+
@inherit = Component::Unknown
|
|
50
|
+
@tags = Hash.new { |hash, key| hash[key] = [] }
|
|
51
|
+
@logs = []
|
|
52
|
+
@refs = []
|
|
53
|
+
@start_time = 0
|
|
54
|
+
@end_time = 0
|
|
55
|
+
@error_occurred = false
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def start
|
|
59
|
+
@stack_depth += 1
|
|
60
|
+
return if @stack_depth != 1
|
|
61
|
+
|
|
62
|
+
@start_time = (Process.clock_gettime(Process::CLOCK_REALTIME) * 1000).to_i
|
|
63
|
+
@context.start(self)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def stop?
|
|
67
|
+
@stack_depth -= 1
|
|
68
|
+
return false unless @stack_depth.zero?
|
|
69
|
+
|
|
70
|
+
@context.stop?(self)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def finish?(segment)
|
|
74
|
+
@end_time = (Process.clock_gettime(Process::CLOCK_REALTIME) * 1000).to_i
|
|
75
|
+
segment.archive(self)
|
|
76
|
+
|
|
77
|
+
true
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def tag(tag)
|
|
81
|
+
if tag.insert
|
|
82
|
+
@tags[tag.key] = tag
|
|
83
|
+
else
|
|
84
|
+
@tags[tag.key] << tag
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def tags_item
|
|
89
|
+
@tags.values.map { |tag| KeyStringValuePair.new(key: tag.key, value: tag.val) }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def inject
|
|
93
|
+
raise 'can only inject context carrier into ExitSpan, this may be a potential bug in the agent, ' \
|
|
94
|
+
'please report this in https://github.com/apache/skywalking/issues if you encounter this. '
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def extract(carrier)
|
|
98
|
+
return self if carrier.nil?
|
|
99
|
+
|
|
100
|
+
@context.segment.relate(carrier.trace_id)
|
|
101
|
+
@context.correlation = carrier.correlation_carrier.correlation
|
|
102
|
+
|
|
103
|
+
return self unless carrier.valid?
|
|
104
|
+
|
|
105
|
+
ref = SegmentRef.new(carrier)
|
|
106
|
+
@refs << ref unless @refs.include?(ref)
|
|
107
|
+
self
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright ownership.
|
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
|
6
|
+
# the License. You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require_relative 'span'
|
|
17
|
+
require_relative 'entry_span'
|
|
18
|
+
require_relative 'exit_span'
|
|
19
|
+
require_relative 'carrier'
|
|
20
|
+
require_relative '../reporter/report'
|
|
21
|
+
|
|
22
|
+
module Skywalking
|
|
23
|
+
module Tracing
|
|
24
|
+
class SpanContext
|
|
25
|
+
include Log::Logging
|
|
26
|
+
|
|
27
|
+
attr_accessor :segment, :span_id, :correlation, :n_spans, :create_time
|
|
28
|
+
|
|
29
|
+
def initialize
|
|
30
|
+
@segment = Tracing::Segment.new
|
|
31
|
+
@span_id = -1
|
|
32
|
+
@correlation = {}
|
|
33
|
+
@n_spans = 0
|
|
34
|
+
@create_time = (Process.clock_gettime(Process::CLOCK_REALTIME) * 1000).to_i
|
|
35
|
+
@primary_endpoint = nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def cfg
|
|
39
|
+
@config ||= ::Skywalking::Agent.config
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def ignore_check(operation, carrier: nil)
|
|
43
|
+
if cfg[:re_ignore_operation].match?(operation) || carrier&.suppressed?
|
|
44
|
+
return Tracing::NoopSpan
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def peek
|
|
51
|
+
spans = ContextManager.spans
|
|
52
|
+
return spans.last unless spans.empty?
|
|
53
|
+
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def new_span(span_klass, parent, **kwargs)
|
|
58
|
+
finished = parent && !parent.stack_depth
|
|
59
|
+
context = finished ? SpanContext.new : self
|
|
60
|
+
|
|
61
|
+
span = span_klass.new(
|
|
62
|
+
span_id: context.span_id += 1,
|
|
63
|
+
parent_id: parent && !finished ? parent.span_id : -1,
|
|
64
|
+
context: context,
|
|
65
|
+
**kwargs
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
if finished
|
|
69
|
+
carrier = Carrier.new(
|
|
70
|
+
trace_id: parent.context.segment.related_traces[0],
|
|
71
|
+
segment_id: parent.context.segment.segment_id,
|
|
72
|
+
span_id: parent.span_id,
|
|
73
|
+
service: cfg[:service_name],
|
|
74
|
+
service_instance: cfg[:instance_name],
|
|
75
|
+
endpoint: parent.operation,
|
|
76
|
+
peer: parent.peer,
|
|
77
|
+
correlation: parent.context.correlation
|
|
78
|
+
)
|
|
79
|
+
span.extract(carrier)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
span
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def new_entry_span(operation, carrier: nil, inherit: nil)
|
|
86
|
+
span = ignore_check(operation)
|
|
87
|
+
return span if span
|
|
88
|
+
|
|
89
|
+
parent = peek
|
|
90
|
+
info 'create new entry span'
|
|
91
|
+
if parent && parent.kind == Kind::Entry && inherit == parent.component
|
|
92
|
+
span = parent
|
|
93
|
+
span.operation = operation
|
|
94
|
+
else
|
|
95
|
+
span = new_span(EntrySpan, parent, operation: operation)
|
|
96
|
+
span.extract(carrier) if carrier&.valid?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
span
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def new_local_span(operation)
|
|
103
|
+
span = ignore_check(operation)
|
|
104
|
+
return span if span
|
|
105
|
+
|
|
106
|
+
parent = peek
|
|
107
|
+
info 'create new local span'
|
|
108
|
+
new_span(Span, parent, operation: operation, kind: Kind::Local)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def new_exit_span(operation, peer, component: nil, inherit: nil)
|
|
112
|
+
span = ignore_check(operation)
|
|
113
|
+
return span if span
|
|
114
|
+
|
|
115
|
+
parent = peek
|
|
116
|
+
info 'create new exit span'
|
|
117
|
+
|
|
118
|
+
if parent && parent.kind == Kind::Exit && inherit == parent.inherit
|
|
119
|
+
span = parent
|
|
120
|
+
span.operation = operation
|
|
121
|
+
span.peer = peer
|
|
122
|
+
span.component = component
|
|
123
|
+
else
|
|
124
|
+
span = new_span(ExitSpan, parent, operation: operation, peer: peer, component: component)
|
|
125
|
+
end
|
|
126
|
+
span.inherit = inherit if inherit
|
|
127
|
+
|
|
128
|
+
span
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def start(span)
|
|
132
|
+
@n_spans += 1
|
|
133
|
+
spans = ContextManager.spans_dup
|
|
134
|
+
unless spans.include?(span)
|
|
135
|
+
spans << span
|
|
136
|
+
if @primary_endpoint.nil?
|
|
137
|
+
@primary_endpoint = PrimaryEndpoint.new(span)
|
|
138
|
+
else
|
|
139
|
+
@primary_endpoint.set_primary_endpoint(span)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def stop?(span)
|
|
145
|
+
spans = ContextManager.spans_dup
|
|
146
|
+
span.finish?(@segment)
|
|
147
|
+
spans.delete(span)
|
|
148
|
+
@n_spans -= 1
|
|
149
|
+
if @n_spans.zero?
|
|
150
|
+
Reporter::Report.trigger << @segment
|
|
151
|
+
return true
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
false
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def active_span
|
|
158
|
+
peek
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
class PrimaryEndpoint
|
|
162
|
+
def initialize(span)
|
|
163
|
+
@span = span
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def set_primary_endpoint(span)
|
|
167
|
+
if @span.kind != Kind::Entry && span.kind == Kind::Entry
|
|
168
|
+
@span = span
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def get_name
|
|
173
|
+
@span.operation
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
class ContextManager
|
|
179
|
+
class << self
|
|
180
|
+
def spans
|
|
181
|
+
Thread.current[:spans] ||= []
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def spans_dup
|
|
185
|
+
spans_dup = spans.dup
|
|
186
|
+
Thread.current[:spans] = spans_dup
|
|
187
|
+
|
|
188
|
+
spans_dup
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def reset_spans
|
|
192
|
+
Thread.current[:spans] = []
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def current_context
|
|
196
|
+
spans_ret = spans
|
|
197
|
+
if spans_ret.any?
|
|
198
|
+
spans.last.context
|
|
199
|
+
else
|
|
200
|
+
SpanContext.new
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def new_exit_span(operation:, peer: nil, component: nil, &block)
|
|
205
|
+
context = current_context
|
|
206
|
+
span = context.new_exit_span(operation, peer, component: component)
|
|
207
|
+
span&.start
|
|
208
|
+
|
|
209
|
+
begin
|
|
210
|
+
yield span if block_given?
|
|
211
|
+
ensure
|
|
212
|
+
span&.stop?
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def new_entry_span(operation:, carrier: nil, inherit: nil, &block)
|
|
217
|
+
context = current_context
|
|
218
|
+
span = context.new_entry_span(operation, carrier: carrier, inherit: inherit)
|
|
219
|
+
span&.start
|
|
220
|
+
|
|
221
|
+
begin
|
|
222
|
+
yield span if block_given?
|
|
223
|
+
ensure
|
|
224
|
+
span&.stop?
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def new_local_span(operation:, &block)
|
|
229
|
+
context = current_context
|
|
230
|
+
span = context.new_local_span(operation)
|
|
231
|
+
span&.start
|
|
232
|
+
|
|
233
|
+
begin
|
|
234
|
+
yield span if block_given?
|
|
235
|
+
ensure
|
|
236
|
+
span&.stop?
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright ownership.
|
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
|
6
|
+
# the License. You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
module Skywalking
|
|
17
|
+
module Tracing
|
|
18
|
+
class Tag
|
|
19
|
+
attr_accessor :val
|
|
20
|
+
attr_reader :key, :insert
|
|
21
|
+
|
|
22
|
+
def initialize(val)
|
|
23
|
+
@val = val.to_s
|
|
24
|
+
@insert = true
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class TagHttpMethod < Tag
|
|
29
|
+
def initialize(val)
|
|
30
|
+
super
|
|
31
|
+
@key = 'http.method'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class TagHttpURL < Tag
|
|
36
|
+
def initialize(val)
|
|
37
|
+
super
|
|
38
|
+
@key = 'http.url'
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class TagDbType < Tag
|
|
43
|
+
def initialize(val)
|
|
44
|
+
super
|
|
45
|
+
@key = 'db.type'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright ownership.
|
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
|
6
|
+
# the License. You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require 'securerandom'
|
|
17
|
+
|
|
18
|
+
module Skywalking
|
|
19
|
+
module Utils
|
|
20
|
+
class IDGen
|
|
21
|
+
def initialize(raw_id: nil)
|
|
22
|
+
@value = raw_id || SecureRandom.uuid.delete('-')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_s
|
|
26
|
+
@value
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright ownership.
|
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
|
6
|
+
# the License. You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
module Skywalking
|
|
17
|
+
VERSION = "0.0.0.alpha".freeze
|
|
18
|
+
end
|
data/lib/skywalking.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright ownership.
|
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
|
6
|
+
# the License. You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require_relative 'skywalking/log/logger'
|
|
17
|
+
require_relative 'skywalking/agent'
|
|
18
|
+
|
|
19
|
+
module Skywalking
|
|
20
|
+
class << self
|
|
21
|
+
def start(config = nil)
|
|
22
|
+
if started?
|
|
23
|
+
return
|
|
24
|
+
end
|
|
25
|
+
Agent.start(config)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def started?
|
|
29
|
+
Agent.started?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def stop
|
|
33
|
+
Agent.stop
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|