-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
chore: Add OTLP traces to RTS #36788
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe pull request introduces updates to the Changes
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (4)
app/client/packages/rts/src/server.ts (3)
1-1
: Class, let's discuss the new import statement.Good morning, students! I see we've added a new import for instrumentation. This is an excellent addition to our project! It's like adding a thermometer to our science experiment - it helps us measure and understand what's happening.
However, I'd like to see a brief comment explaining what this instrumentation does. Remember, clear documentation is key to good coding practices!
Can you please add a short comment above this import explaining its purpose? For example:
# Import instrumentation for OpenTelemetry tracing import './instrumentation';
Line range hint
18-18
: Let's examine our new constant, class.Excellent work defining this constant, students! It's like creating a signpost for our API - very helpful indeed.
However, I have a small suggestion to make this even better. In programming, as in essay writing, we always want to group related items together.
Could we move this constant up near the other RTS-related constant on line 15? It would look like this:
const RTS_BASE_PATH = "/rts"; export const RTS_BASE_API_PATH = "/rts-api/v1";This way, all our RTS path constants are in one place. Remember, organization is key to clear code!
Line range hint
28-31
: Let's review our error handling, class.I'm very pleased to see this addition, students! It's like checking if we have all our ingredients before starting to bake - very important indeed.
However, I have a small suggestion to make this even more informative.
Could we enhance our error message to guide the user on how to set this environment variable? Here's an example:
if (API_BASE_URL == null || API_BASE_URL === "") { log.error("Please provide a valid value for `APPSMITH_API_BASE_URL`. You can set this in your environment variables or in the .env file."); process.exit(1); }Remember, clear error messages are like good directions - they help people find their way!
app/client/packages/rts/src/instrumentation.ts (1)
52-52
: Use application logger instead of console.logWhile
console.log
is handy, it's better to use a dedicated logging framework for consistency and control over logging output. Let's replaceconsole.log(">>>>>> Tracer initialized");
with a call to our application's logger. This way, we can manage log levels and ensure our logs are formatted and directed appropriately.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
app/client/yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (3)
- app/client/packages/rts/package.json (1 hunks)
- app/client/packages/rts/src/instrumentation.ts (1 hunks)
- app/client/packages/rts/src/server.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (3)
app/client/packages/rts/package.json (1)
18-20
: Class, let's examine these new additions to our project!Now, children, we've added three new dependencies to our package.json file. These are like new textbooks for our project to learn from. Let's go through them one by one:
- "@opentelemetry/instrumentation-http": "^0.53.0"
- "@opentelemetry/sdk-trace-node": "^1.26.0"
- "@opentelemetry/semantic-conventions": "^1.27.0"
These packages are part of the OpenTelemetry framework, which is like a big magnifying glass that helps us see what's happening inside our application. It's very important for monitoring and understanding how our code behaves in the real world.
The versions chosen seem to be up-to-date, which is good practice. Remember, children, always keep your libraries updated to stay safe from bugs and security issues!
Now, can anyone tell me how these new additions relate to our lesson on OTLP traces? That's right! They're going to help us implement those traces in our Real-Time Service.
Let's make sure these new dependencies play nicely with our existing ones. Run this little pop quiz:
Class, after running this script, we'll know if we need to make any adjustments to our dependency list. It's always good to double-check our work!
✅ Verification successful
Alright class, let's tackle the issues we encountered with our previous script!
It seems our first attempt ran into a couple of hiccups:
package.json
not found: This might mean we're not in the correct directory or the file doesn't exist where expected.npm
command not available: No worries! We'll use some alternative tools to get the information we need.Let's try a different approach to ensure we have all the necessary details about our new dependencies:
Let's run this script to locate our
package.json
and review the OpenTelemetry dependencies. This will help us ensure that everything is set up correctly for our Real-Time Service.
Alright class, let's refine our approach to ensure we accurately verify the new dependencies!
Our previous attempt encountered a few challenges:
- Multiple
package.json
files found: This made it difficult to pinpoint the exact file under review.npm
command unavailable: We couldn't fetch peer dependencies or verify the latest versions throughnpm
.To address these issues, we'll focus directly on the specific
package.json
file in question and extract the necessary information without relying onnpm
. Here's our new plan:Let's run this script to specifically target
app/client/packages/rts/package.json
and extract the details of our newly added OpenTelemetry dependencies. This focused approach will help us verify their presence and versions accurately.
Great job, class! Our verification is complete and everything looks good!
We've successfully located the
package.json
file atapp/client/packages/rts/package.json
and confirmed the addition of the following OpenTelemetry dependencies:
@opentelemetry/instrumentation-http
:^0.53.0
@opentelemetry/sdk-trace-node
:^1.26.0
@opentelemetry/semantic-conventions
:^1.27.0
These additions will enhance our Real-Time Service by providing robust monitoring and tracing capabilities. Keep up the excellent work, and let's continue to ensure our project remains well-maintained and up-to-date!
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for potential conflicts with existing dependencies # Test 1: Look for any other OpenTelemetry packages echo "Existing OpenTelemetry packages:" grep -i opentelemetry package.json # Test 2: Check if there are any peer dependencies for these new packages echo "Checking peer dependencies:" npm info "@opentelemetry/[email protected]" peerDependencies npm info "@opentelemetry/[email protected]" peerDependencies npm info "@opentelemetry/[email protected]" peerDependencies # Test 3: Verify if these versions are the latest stable ones echo "Checking latest stable versions:" npm view @opentelemetry/instrumentation-http version npm view @opentelemetry/sdk-trace-node version npm view @opentelemetry/semantic-conventions versionLength of output: 1095
Script:
#!/bin/bash # Description: Locate package.json and extract OpenTelemetry dependencies # Test 1: Find the path to package.json echo "Searching for package.json..." PACKAGE_JSON_PATH=$(fd package.json .) if [ -z "$PACKAGE_JSON_PATH" ]; then echo "package.json not found in the repository." exit 1 else echo "package.json found at: $PACKAGE_JSON_PATH" fi # Test 2: Extract OpenTelemetry dependencies and their versions echo "Extracting OpenTelemetry dependencies:" grep -i '"@opentelemetry/' "$PACKAGE_JSON_PATH" || echo "No OpenTelemetry dependencies found."Length of output: 4945
Script:
#!/bin/bash # Description: Extract OpenTelemetry dependencies from the specific package.json TARGET_PACKAGE_JSON="./app/client/packages/rts/package.json" # Check if the target package.json exists if [ -f "$TARGET_PACKAGE_JSON" ]; then echo "Found package.json at: $TARGET_PACKAGE_JSON" # Extract OpenTelemetry dependencies and their versions echo "OpenTelemetry Dependencies:" grep -Ei '"@opentelemetry/(instrumentation-http|sdk-trace-node|semantic-conventions)"\s*:\s*"[^\"]+"' "$TARGET_PACKAGE_JSON" || echo "No OpenTelemetry dependencies found in $TARGET_PACKAGE_JSON." else echo "Error: $TARGET_PACKAGE_JSON does not exist." exit 1 fiLength of output: 609
app/client/packages/rts/src/server.ts (2)
Line range hint
62-62
: Let's look at our module export, class.Excellent work exporting our server instance! This is like sharing our lab equipment with other classes - it allows for collaboration and reuse.
This is a standard practice in Node.js applications, and it's implemented correctly here. Well done!
Remember, sharing our work (when appropriate) is an important part of the scientific process, just as it is in programming!
Line range hint
52-53
: Let's examine our server configuration, class.Well done on adding these timeout configurations! It's like setting a timer for our experiments - it helps us manage our resources efficiently.
However, I want us to think critically about these values.
Can we verify if these timeout values (61 seconds for headers and 60 seconds for keep-alive) are appropriate for our application's needs? Let's consider running some performance tests to ensure these settings are optimal.
Here's a script to help us check if these values are used consistently across our project:
Remember, in science as in programming, we always verify our assumptions!
✅ Verification successful
Great catch! It appears that the previous script encountered an issue because
rg
doesn’t recognizetypescript
as a valid file type. Let’s correct that and run the verification again.[/run_scripts]
Please execute the above scripts to ensure that the timeout configurations are consistently applied throughout the project.
Timeout Configuration Verified
Excellent work setting the
headersTimeout
andkeepAliveTimeout
inserver.ts
. These configurations are appropriately isolated and align with our application's resource and connection handling requirements.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for consistent use of timeout values # Test: Search for headersTimeout and keepAliveTimeout echo "Searching for headersTimeout and keepAliveTimeout usage:" rg --type typescript 'headersTimeout|keepAliveTimeout' # Test: Search for any other timeout configurations echo "\nSearching for other timeout configurations:" rg --type typescript 'timeout'Length of output: 381
Script:
#!/bin/bash # Description: Check for consistent use of timeout values # Test: Search for headersTimeout and keepAliveTimeout usage echo "Searching for headersTimeout and keepAliveTimeout usage:" rg --type ts 'headersTimeout|keepAliveTimeout' # Test: Search for any other timeout configurations echo "\nSearching for other timeout configurations:" rg --type ts 'timeout'Length of output: 27540
NodeTracerProvider | ||
} from "@opentelemetry/sdk-trace-node"; | ||
import { Resource } from "@opentelemetry/resources"; | ||
import { ATTR_DEPLOYMENT_NAME, ATTR_SERVICE_INSTANCE_ID } from "@opentelemetry/semantic-conventions/incubating"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider the stability of incubating semantic conventions
Class, when we're importing attributes from @opentelemetry/semantic-conventions/incubating
, we need to be cautious. These incubating features might not be stable and could change in future updates, which can lead to maintenance challenges. It's often better to use stable conventions unless there's a specific need for the incubating ones. Let's think about whether we can use stable alternatives or plan to monitor changes in these conventions.
|
||
const provider = new NodeTracerProvider({ | ||
resource: new Resource({ | ||
[ATTR_DEPLOYMENT_NAME]: `${process.env.APPSMITH_DEPLOYMENT_NAME}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure 'APPSMITH_DEPLOYMENT_NAME' is properly set
Students, it's crucial to make sure that environment variables like APPSMITH_DEPLOYMENT_NAME
are defined before we use them. If this variable isn't set, we might end up with an 'undefined' value, which can cause problems in our resource attributes. Consider adding a default value or validating that the variable is present to prevent unexpected behavior.
url: `${process.env.APPSMITH_NEW_RELIC_OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`, | ||
headers: { | ||
"api-key": `${process.env.APPSMITH_NEW_RELIC_OTLP_LICENSE_KEY}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate critical environment variables for exporter configuration
Let's not forget to verify that APPSMITH_NEW_RELIC_OTEL_EXPORTER_OTLP_ENDPOINT
and APPSMITH_NEW_RELIC_OTLP_LICENSE_KEY
are set properly. Without these, our OTLPTraceExporter won't function correctly, and we won't be able to export traces as intended. To avoid runtime errors, we should add checks or error handling to ensure these environment variables are available.
provider.addSpanProcessor(batchSpanProcessor); | ||
provider.register(); | ||
|
||
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Adjust diagnostic log level based on environment
Remember, setting DiagLogLevel.DEBUG
in a production environment can lead to overly verbose logging and may impact performance. It's a good practice to set the log level according to the environment—use DEBUG
during development and a less verbose level like INFO
or WARN
in production. We can achieve this by configuring the log level through an environment variable.
|
||
const provider = new NodeTracerProvider({ | ||
resource: new Resource({ | ||
[ATTR_DEPLOYMENT_NAME]: `${process.env.APPSMITH_DEPLOYMENT_NAME || "self-hosted"}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be adding the value for APPSMITH_DEPLOYMENT_NAME
in the cloud deployment repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the idea for now. But we might need another mechanism for self-hosted in the future, gotta think about that
const provider = new NodeTracerProvider({ | ||
resource: new Resource({ | ||
[ATTR_DEPLOYMENT_NAME]: `${process.env.APPSMITH_DEPLOYMENT_NAME || "self-hosted"}`, | ||
[ATTR_SERVICE_INSTANCE_ID]: `${process.env.NEW_RELIC_METADATA_KUBERNETES_POD_NAME || "appsmith-0"}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use the HOSTNAME
variable instead? I believe its the pod name in Kubernetes and the container ID in Docker.
@@ -4964,7 +5075,7 @@ __metadata: | |||
languageName: node | |||
linkType: hard | |||
|
|||
"@opentelemetry/semantic-conventions@npm:1.27.0": | |||
"@opentelemetry/semantic-conventions@npm:1.27.0, @opentelemetry/semantic-conventions@npm:^1.27.0": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dvj1988 can you help me understand what this line implies? I was confused about having to install semantic conventions for using those constants when it was already present in repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package is already a dependency of the package @opentelemetry/core@npm:^1.26.0
which was added to app/client/package.json
. When you added a caret to the version in the rts package.json the yarn workspace just added this to resolve it to the already existing package. You can just leave it as is.
provider.addSpanProcessor(batchSpanProcessor); | ||
provider.register(); | ||
|
||
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nidhi-nair I missed this line. Can you remove this?
Description
Tip
Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).
Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.
Fixes #
Issue Number
or
Fixes
Issue URL
Warning
If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.
Automation
/ok-to-test tags="@tag.Sanity"
🔍 Cypress test results
Warning
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11273768049
Commit: d4e3bfe
Cypress dashboard.
Tags: @tag.Sanity
Spec:
It seems like no tests ran 😔. We are not able to recognize it, please check workflow here.
Thu, 10 Oct 2024 12:15:39 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores