Skip to content

Please reintroduce context.Context #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Azuka opened this issue Aug 10, 2024 · 5 comments · May be fixed by twilio/twilio-oai-generator#651 or #287
Open

Please reintroduce context.Context #255

Azuka opened this issue Aug 10, 2024 · 5 comments · May be fixed by twilio/twilio-oai-generator#651 or #287
Labels
priority: low Nice-to-have; can wait priority: medium Important but not urgent; Workaround available type: twilio enhancement feature request on Twilio's roadmap

Comments

@Azuka
Copy link

Azuka commented Aug 10, 2024

Issue Summary

This is a duplicate of #98 which has been closed with no update. context.Context support was introduced in https://github.com/twilio/twilio-go/blob/main/CHANGES.md#2022-11-10-version-120 then mysteriously reverted

Steps to Reproduce

N/A

Code Snippet

N/A

Exception/Log

N/A

Technical details:

  • twilio-go version: 1.22.3
  • go version: 1.22
@manisha1997 manisha1997 added priority: medium Important but not urgent; Workaround available priority: low Nice-to-have; can wait labels Apr 17, 2025
@devnev
Copy link

devnev commented May 16, 2025

Running into this issue as it also prevents tracing from working properly

@Hades32
Copy link

Hades32 commented May 16, 2025

This is really pretty annoying. We are now creating a new client with this workaround:

// forceContextRoundTripper sets the given context on every request and passes it to the wrapped RoundTripper
type forceContextRoundTripper struct {
	roundTripper http.RoundTripper
	ctx          context.Context
}

func (f *forceContextRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
	req = req.Clone(f.ctx)
	return f.roundTripper.RoundTrip(req)
}

// NewClient creates a twilio client whose HTTP requests are bound by the passed context.
// This is required because their package doesn't expose the context param per operation...
func NewClient(ctx context.Context) *twilio.RestClient {
	c := twilio.NewRestClientWithParams(twilio.ClientParams{
		Username: env.TwilioAccountSid,
		Password: env.TwilioAuthToken,
	})
	httpClient := utils.NewHttpClient(5*time.Second, 100)
	httpClient.Transport = &forceContextRoundTripper{
		ctx:          ctx,
		roundTripper: httpClient.Transport,
	}
	c.RequestHandler.Client.(*twilioClient.Client).HTTPClient = httpClient
	return c
}

@tiwarishubham635 tiwarishubham635 added the type: twilio enhancement feature request on Twilio's roadmap label May 16, 2025
@tiwarishubham635
Copy link
Contributor

Hi! We have added this request (DII-1926) to our internal backlog. +1/upvotes will help bring this up the priority. Thanks!

@devnev
Copy link

devnev commented May 16, 2025

@Hades32 Nice, so you make a new client for every incoming request to associate the requests made by the client with the original request? Hacky but workable, thanks

@manisha1997 manisha1997 linked a pull request May 19, 2025 that will close this issue
14 tasks
@manisha1997
Copy link
Contributor

We are actively working on this. We will try to release this as soon as possible

@manisha1997 manisha1997 linked a pull request May 19, 2025 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low Nice-to-have; can wait priority: medium Important but not urgent; Workaround available type: twilio enhancement feature request on Twilio's roadmap
Projects
None yet
5 participants