Skip to content

feat(contrib/cloud.google.com/go/pubsub.v2): support cloud.google.com/go/pubsub/v2#3841

Merged
dd-mergequeue[bot] merged 10 commits into
DataDog:mainfrom
shota3506:cloud.google.com-go-pubsub-v2
Aug 26, 2025
Merged

feat(contrib/cloud.google.com/go/pubsub.v2): support cloud.google.com/go/pubsub/v2#3841
dd-mergequeue[bot] merged 10 commits into
DataDog:mainfrom
shota3506:cloud.google.com-go-pubsub-v2

Conversation

@shota3506

@shota3506 shota3506 commented Aug 4, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR adds a new package, contrib/cloud.google.com/go/pubsub.v2, which provides functions to trace the cloud.google.com/go/pubsub/v2 package.

The implementation is largely based on the existing contrib/cloud.google.com/go/pubsub.v1 package, with necessary updates to align with the library's official v2 migration guide.

The original contrib/cloud.google.com/go/pubsub.v1 package is retained as per the contribution guidelines.

Motivation

#3840

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running ./scripts/lint.sh locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

@shota3506
shota3506 force-pushed the cloud.google.com-go-pubsub-v2 branch from c8b74c5 to 59542fc Compare August 4, 2025 08:40

"cloud.google.com/go/pubsub"
"cloud.google.com/go/pubsub/pstest"
"cloud.google.com/go/pubsub/v2"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

replaced v1 test because we cannot import both "cloud.google.com/go/pubsub" and "cloud.google.com/go/pubsub/v2" at the same time

panic: proto: file "google/pubsub/v1/schema.proto" is already registered

                previously from: "cloud.google.com/go/pubsub/apiv1/pubsubpb"

                currently from:  "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"

        See https://protobuf.dev/reference/go/faq#namespace-conflict

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.

would it be possible to do it in a different package? similar as how it is done in confluent-kafka-go v1 and v2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see, moved the pubsub v1 test to a different pacakge

@shota3506

Copy link
Copy Markdown
Contributor Author

Is there anything I need to do to support orchestrion?

_ "github.com/DataDog/dd-trace-go/contrib/cloud.google.com/go/pubsub.v1/v2" // integration

@shota3506
shota3506 marked this pull request as ready for review August 4, 2025 08:47
@shota3506
shota3506 requested review from a team as code owners August 4, 2025 08:47
@rarguelloF rarguelloF self-assigned this Aug 4, 2025
Comment thread contrib/cloud.google.com/go/pubsub.v2/go.mod Outdated
Comment thread ddtrace/tracer/option.go
"github.com/aws/aws-sdk-go-v2": {"AWS SDK v2", false},
"github.com/bradfitz/gomemcache": {"Memcache", false},
"cloud.google.com/go/pubsub.v1": {"Pub/Sub", false},
"cloud.google.com/go/pubsub/v2": {"Pub/Sub v2", false},

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.

Suggested change
"cloud.google.com/go/pubsub/v2": {"Pub/Sub v2", false},
"cloud.google.com/go/pubsub.v2": {"Pub/Sub v2", false},

@shota3506 shota3506 Aug 12, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I though the map key should be valid external go package name. The map is referred in MarkIntegrationImported and it looks expect go package name.

I guess cloud.google.com/go/pubsub.v1 is wrong?


"cloud.google.com/go/pubsub"
"cloud.google.com/go/pubsub/pstest"
"cloud.google.com/go/pubsub/v2"

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.

would it be possible to do it in a different package? similar as how it is done in confluent-kafka-go v1 and v2

@@ -0,0 +1,103 @@
# Unless explicitly stated otherwise all files in this repository are licensed

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.

if adding Orchestrion support we need to add an orchestrion integration test in internal/orchestrion/_integration

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rarguelloF
Thank you.

One question about module dependencies.
./instrumentation/internal/namingschematest/go.mod and ./orchestriion/all/go.mod refers to contrib modules tagged v2.3.0-dev.1.
How can I add github.com/DataDog/dd-trace-go/contrib/cloud.google.com/go/pubsub.v2/v2 to these go.mod files? Should I split PRs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've excluded changes for namingschematest and orchestrion in this PR because I couldn't find a way to add the new contrib package to ./instrumentation/internal/namingschematest/go.mod and ./orchestriion/all/go.mod.
Let me know how to do that if it's possible.

// The motivation of this package is to support orchestrion, which cannot use the main package because it imports
// the cloud.google.com/go/pubsub/v2 package, and since orchestrion modifies the library code itself,
// this would cause an import cycle.
package tracing

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.

it seems this package is pretty much the same as the one in v1. Could we reuse it to work for both v1 and v2 under contrib/cloud.google.com/go/pubsubtrace? (you can check contrib/confluentinc/confluent-kafka-go/kafkatrace as reference where we did something similar)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added contrib/cloud.google.com/go/pubsubtrace package.
Please review the interface change of TracePublish and TraceReceiveFunc.

contrib/confluentinc/confluent-kafka-go/kafkatrace defines package version enum CKGoVersion and accept it in NewKafkaTracer. Should I do something similar instead of accepting componentName instrumentation.Package in TracePublish and TraceReceiveFunc?

@shota3506
shota3506 force-pushed the cloud.google.com-go-pubsub-v2 branch from c0c6131 to 94e27d6 Compare August 12, 2025 03:47
@shota3506
shota3506 requested a review from rarguelloF August 14, 2025 01:31
@leifode

leifode commented Aug 21, 2025

Copy link
Copy Markdown

We are also interesting in getting this merged due to the deprecation of pubsub v1... Anything we can do to support this? :)

@shota3506

Copy link
Copy Markdown
Contributor Author

@rarguelloF Could you please review my PR? Are there any blockers?

@rarguelloF rarguelloF changed the title contrib/cloud.google.com/go/pubsub.v2: support cloud.google.com/go/pubsub/v2 feat(contrib/cloud.google.com/go/pubsub.v2): support cloud.google.com/go/pubsub/v2 Aug 25, 2025
@rarguelloF

Copy link
Copy Markdown
Contributor

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Aug 26, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-08-26 12:24:38 UTC ℹ️ Start processing command /merge


2025-08-26 12:24:52 UTC ℹ️ MergeQueue: waiting for PR to be ready

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-08-26 14:35:24 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in main is approximately 14m (p90).


2025-08-26 14:49:14 UTC ℹ️ MergeQueue: This merge request was merged

@rarguelloF

Copy link
Copy Markdown
Contributor

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Aug 26, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-08-26 14:09:43 UTC ℹ️ Start processing command /merge


2025-08-26 14:09:59 UTC ❌ MergeQueue

PR already in the queue with status waiting

@dd-mergequeue
dd-mergequeue Bot merged commit c7f78ea into DataDog:main Aug 26, 2025
131 checks passed
@shota3506
shota3506 deleted the cloud.google.com-go-pubsub-v2 branch August 28, 2025 04:29
@ztkent

ztkent commented Sep 9, 2025

Copy link
Copy Markdown

Having an issue using this functionality.

The pubsub trace module is not configured correctly.

go get github.com/DataDog/dd-trace-go/contrib/cloud.google.com/go/pubsub.v2/v2
go: github.com/DataDog/dd-trace-go/contrib/cloud.google.com/go/pubsub.v2/v2 imports
        github.com/DataDog/dd-trace-go/v2/contrib/cloud.google.com/go/pubsubtrace: cannot find module providing package github.com/DataDog/dd-trace-go/v2/contrib/cloud.google.com/go/pubsubtrace
go get github.com/DataDog/dd-trace-go/v2/contrib/cloud.google.com/go/pubsubtrace
go: module github.com/DataDog/dd-trace-go/v2@upgrade found (v2.2.3), but does not contain package github.com/DataDog/dd-trace-go/v2/contrib/cloud.google.com/go/pubsubtrace

@leifode

leifode commented Sep 10, 2025

Copy link
Copy Markdown

Having an issue using this functionality.

The pubsub trace module is not configured correctly.

go get github.com/DataDog/dd-trace-go/contrib/cloud.google.com/go/pubsub.v2/v2
go: github.com/DataDog/dd-trace-go/contrib/cloud.google.com/go/pubsub.v2/v2 imports
        github.com/DataDog/dd-trace-go/v2/contrib/cloud.google.com/go/pubsubtrace: cannot find module providing package github.com/DataDog/dd-trace-go/v2/contrib/cloud.google.com/go/pubsubtrace
go get github.com/DataDog/dd-trace-go/v2/contrib/cloud.google.com/go/pubsubtrace
go: module github.com/DataDog/dd-trace-go/v2@upgrade found (v2.2.3), but does not contain package github.com/DataDog/dd-trace-go/v2/contrib/cloud.google.com/go/pubsubtrace

@ztkent, as stated here - #3840 (reply in thread) - this functionality will be part of the v2.3.0-release due by the end of SEP2025. Hence, you will have to wait for that release to start using this functionality...:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants