Skip to content
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

Add Forge runtime transport #3669

Closed
wants to merge 11 commits into from

Conversation

1999
Copy link
Contributor

@1999 1999 commented Jun 11, 2021

This is a follow-up to #3655. This PR has the real Forge runtime transport implementation. If this PR gets merged, my next PR will be a change to the documentation. It will contain detailed information on how to use this transport in Forge runtime.

cc @nvenegas

@1999 1999 requested a review from kamilogorek as a code owner June 11, 2021 12:05
@1999
Copy link
Contributor Author

1999 commented Jun 11, 2021

Meh, sorry for this. Looks like we have a blocker on our side for this PR: https://ecosystem.atlassian.net/browse/FRGE-273
I will try to push it.

@1999 1999 changed the title Add Forge runtime transport [Blocked] Add Forge runtime transport Jun 11, 2021
@1999 1999 force-pushed the dsorin/forge-add-transport branch from a8b293c to aadce0b Compare June 16, 2021 09:21
@1999 1999 mentioned this pull request Jun 16, 2021
@1999
Copy link
Contributor Author

1999 commented Jun 18, 2021

Update on the blocking dependencies:

  • @forge/storage transitive dependency won't have "engines" restriction starting from its next patch release which is scheduled for June 29th
  • PR to @forge/api to export simple types instead of type-only imports is in review and I'm hoping to get it merged by June 29th as well.

1999 added 2 commits June 25, 2021 17:01
…transport

* upstream/master: (29 commits)
  ref: Always use lowercase files (getsentry#3742)
  feat: Make dedupe integration default for browser (getsentry#3730)
  ref(ember): Allow initing Ember without config entry (getsentry#3745)
  fix(serverless): wrapEventFunction does not await for async code (getsentry#3740)
  Metrics: Tag CLS elements (getsentry#3734)
  feat: Add Next.js 11 to supported peer dependencies list (getsentry#3711)
  test: Run integration tests for Next 10/11 and Webpack 4/5 matrix (getsentry#3741)
  fix: Correctly limit Buffer requests (getsentry#3736)
  Whoops. Remove pinned node version from package.json
  ref: Introduce test runner for node session health tests (getsentry#3728)
  fix: Prevent circular structure serialization in events (getsentry#3727)
  ref(node): Update Node manual tests and test for sessionCount (getsentry#3726)
  ref(ember): Update scenarios and remove a few to speed up tests (getsentry#3720)
  docs: Fix typos (getsentry#3716)
  fix(ember): Fix ember test flake (getsentry#3719)
  release: 6.7.2
  ci: fix ember flaky test (getsentry#3718)
  misc: changelog for release 6.7.2 (getsentry#3717)
  fix(release-health): Prevent sending terminal status session updates (getsentry#3701)
  ref: Make beforeSend more strict (getsentry#3713)
  ...
@1999
Copy link
Contributor Author

1999 commented Jun 25, 2021

Happy days. Our changes in the beta branch work fine. On Tuesday next week, we will publish new stable versions of the packages and I will update this PR with these versions.

1999 added 2 commits July 1, 2021 00:09
…transport

* upstream/master:
  fix(tracing): Add check for document.scripts in metrics (getsentry#3766)
  ref(nextjs): Stop setting redundant `productionBrowserSourceMaps` in config (getsentry#3765)
  test: Ensure withScope and run bubble up exceptions (getsentry#3764)
  ref(gatsby): Default release to empty string (getsentry#3759)
  fix(nextjs): Make `withSentryConfig` return type match given config type (getsentry#3760)
  misc: Fix typos (getsentry#3763)
  fix(node): Enable autoSessionTracking correctly (getsentry#3758)
  release: 6.8.0
  meta: 6.8.0 changelog
  feat: Enable serialization of multiple DOM attributes for breadcrumbs. (getsentry#3755)
  ref: Leave only valid buffer implementation (getsentry#3744)
@1999
Copy link
Contributor Author

1999 commented Jun 30, 2021

@kamilogorek okay, it's finally happening :) My changes have been published today and this PR should be ready to review.

@1999 1999 changed the title [Blocked] Add Forge runtime transport Add Forge runtime transport Jun 30, 2021
@1999
Copy link
Contributor Author

1999 commented Jun 30, 2021

Ah, I forgot to replace our company NPM mirror with a public one. Will do in a min.

@1999 1999 force-pushed the dsorin/forge-add-transport branch from 5260abd to 5fcba08 Compare June 30, 2021 14:46
@1999
Copy link
Contributor Author

1999 commented Jun 30, 2021

Alright, it should be fine now.

@1999
Copy link
Contributor Author

1999 commented Jul 2, 2021

Hey @kamilogorek do you need any clarifying comments from me to review this PR? My plan was also to add documentation (https://github.com/getsentry/sentry-docs) after this PR but I can raise a PR in the docs repo in parallel.

@kamilogorek
Copy link
Contributor

Hey @1999, the PR looks good, however after discussing with the team, we decided to not merge it into the main mono-repo in it's current shape (monorepo shape, not your PR). Current SDK architecture makes it quite hard for 3rd party contributions due to everything being stored in the main packages (in opposition to something like a basic plugin system, or per-feature structure like we are planning to do in the future - see: https://github.com/getsentry/sentry-javascript/tree/v7-dev/packages ).
By merging this, we'd make every node user to download parts of the code related to Forge in their codebase, no matter they use it or not (unless they treeshake it, which is not common in node envs). It also extends the support landscape that we'd have to perform, that we simply don't have enough resources for.

Would it be possible that you create a standalone repo/npm package out of this PR instead? I'm more than happy to do necessary changes to the SDK if there are any that'd prevent you from doing that.

Once you do that, we will happily link your package in our documentation with all the necessary explanations and section about Atlassian Forge.

Thanks!

@1999
Copy link
Contributor Author

1999 commented Jul 12, 2021

By merging this, we'd make every node user to download parts of the code related to Forge in their codebase, no matter they use it or not (unless they treeshake it, which is not common in node envs).

I don't quite agree with this. The way how transport is built is by passing Forge fetch function as a parameter. Also, it is a devDependency, therefore Sentry Node users won't download Forge parts.

It also extends the support landscape that we'd have to perform, that we simply don't have enough resources for.

That's a 100% valid reason and I fully agree with you.

Would it be possible that you create a standalone repo/npm package out of this PR instead? I'm more than happy to do necessary changes to the SDK if there are any that'd prevent you from doing that.

I remember that I tried to extract this but there were some types that I needed to heavily rely on and these types were not exported. I will take a look again and comment in this PR on what I will need to export.

@1999
Copy link
Contributor Author

1999 commented Jul 12, 2021

@kamilogorek thanks for finding time to review this. I really appreciate this!

@1999
Copy link
Contributor Author

1999 commented Jul 12, 2021

Looks like I will need these types:

import {
  HTTPModule,
  HTTPModuleClientRequest,
  HTTPModuleRequestIncomingMessage,
  HTTPModuleRequestOptions
} from '@sentry/node/dist/transports/base/http-module';

and also BaseTransport to extend it.

import { BaseTransport } from '@sentry/node/dist/transports';

Do you think it's reasonable if we export these types and class from @sentry/node package?

@kamilogorek
Copy link
Contributor

kamilogorek commented Jul 12, 2021

I think this should already work:

import { Transports } from '@sentry/node';

class ForgeRuntimeTransport extends Transports.BaseTransport {
  // ...
}

as for types, I'll see what we can do there.

@kamilogorek
Copy link
Contributor

I just realized that all the types you mentioned are self-contained and have no cross-references to the rest of the SDK. Because of this, and the fact that it's only 24LoC, it's rather safe and trivial to vendor them.

import { IncomingHttpHeaders, RequestOptions as HTTPRequestOptions } from 'http';
import { RequestOptions as HTTPSRequestOptions } from 'https';
import { URL } from 'url';

export type HTTPModuleRequestOptions = HTTPRequestOptions | HTTPSRequestOptions | string | URL;

export interface HTTPModuleRequestIncomingMessage {
  headers: IncomingHttpHeaders;
  statusCode?: number;
  on(event: 'data' | 'end', listener: () => void): void;
  setEncoding(encoding: string): void;
}

export interface HTTPModuleClientRequest {
  end(chunk: string): void;
  on(event: 'error', listener: () => void): void;
}

export interface HTTPModule {
  request(options: HTTPModuleRequestOptions, callback?: (res: HTTPModuleRequestIncomingMessage) => void): HTTPModuleClientRequest;
}

@1999
Copy link
Contributor Author

1999 commented Jul 14, 2021

@kamilogorek this one is challenging. What part of Sentry Node.JS API is considered "public"? As an example, if you decide to change BaseTransport.module type from HTTPModule to something else, will this be published as a new major version? If not, this makes my external module very fragile as it can work with v6.9.0 but it can break when you publish v6.10.0.

@kamilogorek
Copy link
Contributor

That's a very valid question. We are trying to keep all the public methods/classes and their appropriate configs backward compatible. Eg. a change that you introduced (module) was not a major release, because it will still work just fine with any custom transport created before that release. We'll try to make sure it stays like this indefinitely (or until we do a major bump).

@1999
Copy link
Contributor Author

1999 commented Jul 14, 2021

@kamilogorek

We'll try to make sure it stays like this indefinitely (or until we do a major bump).

Shouldn't exporting types be one of the ways to enforce this? Imagine any of the custom transports created outside Sentry monorepo. The only thing they can rely on is a BaseTransport because it is exported. But what about the types used in this module? (HTTPModule, HTTPModuleClientRequest, HTTPModuleRequestIncomingMessage, HTTPModuleRequestOptions). Should all custom transports just copy them from Sentry repo? Why not just export them and allow custom transports authors to use these types in their code?

@kamilogorek
Copy link
Contributor

I do agree with you, however, after 3 years of this version of SDK being alive, it's the first use-case like this that we had. The reason for this I believe is that BaseTransport covers all the defaults, and even without exposing these types, you can still create your own transport when you don't need to implement module. I just don't want to overflow https://getsentry.github.io/sentry-javascript/modules/node.html with every possible export, as it can get messy. If we'd have more scenarios like this in the past, we'd definitely rethink this approach.

@1999
Copy link
Contributor Author

1999 commented Jul 14, 2021

@kamilogorek fair enough. Thanks for explaining, I will continue with just BaseTransport.

@1999 1999 closed this Jul 14, 2021
@1999 1999 deleted the dsorin/forge-add-transport branch July 29, 2021 05:04
@1999
Copy link
Contributor Author

1999 commented Jul 29, 2021

@kamilogorek good news: we managed to finally publish this custom transport. Here's how it is used in a real Forge app: https://bitbucket.org/atlassian/confluence-recent-edits-overview/src/master/src/sentry.ts.

Do you think it's fine if I add a "Transports" section to Node.JS transport docs as you have for PHP?

@kamilogorek
Copy link
Contributor

Do you think it's fine if I add a "Transports" section to Node.JS transport docs as you have for PHP?

Definitely! I'm out next week, but feel free to assign me (or a whole @getsentry/team-webplatform) for a review and I'll take a look once I'm back.

@1999
Copy link
Contributor Author

1999 commented Jul 31, 2021

@kamilogorek have a great week off!

Here's a PR: getsentry/sentry-docs#3962

@1999
Copy link
Contributor Author

1999 commented Feb 24, 2022

@kamilogorek heads up that with the newest release of Forge CLI it is no longer possible to use Sentry in Forge apps. The root cause is webpack@5 that no longer bundles some polyfills and Sentry SDK for Node relies on "domain". Sad but there's not much I can do so I will have to deprecate the transport package.

@AbhiPrasad
Copy link
Member

Sad to hear, but we opened #4633. Hopefully we can revisit this sometime in the future!

@kamilogorek
Copy link
Contributor

Thanks for the heads-up @1999, appreciate that

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.

3 participants