Skip to content

Add __getnewargs__ to SpanContext class - #1380

Merged
codeboten merged 11 commits into
open-telemetry:masterfrom
rickychu:bug_pickle_support_spancontext
Nov 16, 2020
Merged

Add __getnewargs__ to SpanContext class#1380
codeboten merged 11 commits into
open-telemetry:masterfrom
rickychu:bug_pickle_support_spancontext

Conversation

@rickychu

@rickychu rickychu commented Nov 13, 2020

Copy link
Copy Markdown
Contributor

Description

SpanContext does not support pickle due to missing getnewargs function. Add function to SpanContext.

Fixes # (issue)
#1375

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Tor

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@rickychu
rickychu requested review from a team, aabmass and toumorokoshi and removed request for a team November 13, 2020 04:25

@ocelotl ocelotl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting. Just out of curiosity, what was the use case that made you open this PR, @rickychu?

@rickychu

rickychu commented Nov 13, 2020

Copy link
Copy Markdown
Contributor Author

Interesting. Just out of curiosity, what was the use case that made you open this PR, @rickychu?

I have a multiprocessing script where the pools need to continue with the span context so it has to be pickled.

def processing_data():
    ...
    with tracer.start_as_current_span("processing_data") as span:
        work_items = get_all_work_items_to_process()

    ...
    with multiprocessing.Pool(cpu_limit) as pool:
        pool.map(partial(worker, context=span.get_current_context()), work_items)

Error:
TypeError: new() missing 2 required positional arguments: 'span_id' and 'is_remote'

It works in 0.13b0 with span.get_context()

@toumorokoshi toumorokoshi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

Comment thread opentelemetry-api/tests/trace/test_span_context.py

@codeboten codeboten left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR!

@codeboten
codeboten merged commit f1db112 into open-telemetry:master Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants