Skip to content

Add optional span param to end_span#1039

Merged
estolfo merged 1 commit intoelastic:masterfrom
matheussilvasantos:optional-span-in-end-span
Jul 30, 2021
Merged

Add optional span param to end_span#1039
estolfo merged 1 commit intoelastic:masterfrom
matheussilvasantos:optional-span-in-end-span

Conversation

@matheussilvasantos
Copy link

What does this pull request do?

Add optional span param to end_span

Why is it important?

When using the gem in asynchronous systems, multiple spans will be created in parallel, and they aren't going to finish in the same order they were created. Therefore, to have spans with the correct duration, we need to pass the span we want to finish - in this case, it's the developer responsibility to hold the span created and pass it to end_span.

Usage example:

require "eventmachine"
require "em-http"
require "elastic_apm"

puts "Starting..."

ElasticAPM.start

EM.run do
  ElasticAPM.start_transaction("Transaction")

  count = 0

  ["https://example.com", "https://example.org"].each do |url|
    span = ElasticAPM.start_span("GET #{url}")

    http = EventMachine::HttpRequest.new(url).get

    http.errback do
      ElasticAPM.end_span(span)
      count += 1
    end

    http.callback do
      ElasticAPM.end_span(span)
      count += 1
    end
  end

  timer = EventMachine::PeriodicTimer.new(1) do
    if count == 2
      ElasticAPM.end_transaction
      puts "Stopping..."
      EM.add_timer(5) do
        ElasticAPM.stop
        EM.stop
      end
      timer.cancel
    end
  end
end

Checklist

  • I have signed the Contributor License Agreement.
  • My code follows the style guidelines of this project (See .rubocop.yml)
  • I have rebased my changes on top of the latest master branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have made corresponding changes to the documentation
  • I have updated CHANGELOG.asciidoc
  • I have updated supported-technologies.asciidoc
  • Added an API method or config option? Document in which version this will be introduced
    (I'm not sure on this one)
@ghost
Copy link

ghost commented Jul 9, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-07-29T12:49:04.704+0000

  • Duration: 24 min 2 sec

  • Commit: cbd8b40

Test stats 🧪

Test Results
Failed 0
Passed 46153
Skipped 84
Total 46237

Trends 🧪

Image of Build Times

Image of Tests

@matheussilvasantos matheussilvasantos force-pushed the optional-span-in-end-span branch from 03a8dd4 to ed70de3 Compare July 9, 2021 01:37
Copy link
Contributor

@mikker mikker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wonderful! Great addition. I don't remember anyone else using the agent with EventMachine so keep the fixes and additions coming as you encounter them ❤️

@mikker
Copy link
Contributor

mikker commented Jul 9, 2021

jenkins, run the tests

@matheussilvasantos matheussilvasantos force-pushed the optional-span-in-end-span branch from ed70de3 to deea9c1 Compare July 9, 2021 09:19
@matheussilvasantos matheussilvasantos force-pushed the optional-span-in-end-span branch from deea9c1 to cbd8b40 Compare July 9, 2021 09:21
@matheussilvasantos matheussilvasantos requested a review from mikker July 9, 2021 09:25
@mikker
Copy link
Contributor

mikker commented Jul 9, 2021

jenkins, run the tests

@estolfo estolfo merged commit 6aa9f74 into elastic:master Jul 30, 2021
@estolfo
Copy link
Contributor

estolfo commented Jul 30, 2021

v1v added a commit to v1v/apm-agent-ruby that referenced this pull request Sep 22, 2021
…thub-commands

* upstream/master: (177 commits)
  synchronize json schema specs
  synchronize json schema specs
  synchronize json schema specs
  Update exit span definition (elastic#1154)
  test: synchronizing json specs
  Handle NaN in metrics (elastic#1157)
  Use Socket.gethostname instead (elastic#1155)
  test: synchronizing json specs
  synchronize json schema specs
  Debug instrumenter test (elastic#1146)
  test: synchronizing json specs
  v4.4.0
  Disable instrumenter/metrics spec for now (elastic#1048)
  Fix CpuMem metrics on Alpine (elastic#1057)
  Fix and update changelog
  Add config option log_ecs_formatting (elastic#1053)
  ES Spy: Fake out verification for 7.14+ (elastic#1054)
  synchronize json schema specs
  Add optional span param to end_span (elastic#1039)
  Filter Jenkins branches (elastic#1046)
  ...
estolfo pushed a commit that referenced this pull request Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants