keepcalculator

06 Numbers and Powers

Capture EdTech API Errors Without Learner Data

Card No. 06·43824 · Updated · Standard formula, shown below

This guide shows you how to log and monitor errors from your EdTech API while keeping learner data out of the logs. You’ll learn to redact personal information, structure error payloads, and set up safe logging practices that protect student privacy and comply with data protection principles.

What You’ll Need

  • Access to your API’s codebase (or at least the error-handling middleware)
  • A logging service or a simple log file destination (e.g., stdout, a file, or a cloud logging tool)
  • Basic familiarity with your API’s framework (Express, Django, etc.)
  • A way to test the API (e.g., Postman, curl, or a test suite)

Step-by-Step

  1. Identify all places where errors are caught. Look for try/catch blocks, error-handling middleware, and any place that logs exceptions. Make a list of these locations so you know where to apply changes.
  2. Define what counts as learner data. This includes names, email addresses, student IDs, grades, attendance records, IP addresses, device identifiers, and any custom fields that could identify a person. Also include free-text fields like comments or notes, as they often contain personal information.
  3. Create a redaction utility. Write a function that takes an object and returns a sanitized copy. Replace values of known sensitive keys with a placeholder like [REDACTED]. Also recursively scan nested objects and arrays.
  4. Whitelist safe fields. Instead of trying to block every possible sensitive field, define a list of fields that are safe to log (e.g., errorCode, message, stack, endpoint, method, statusCode). When logging an error, only include these fields plus any non-sensitive metadata you explicitly add.
  5. Redact the error object before logging. In your error handler, take the error and any request context, run it through your redaction utility, and then log the sanitized version. Never log the raw error object or the request body directly.
  6. Strip query parameters and headers. These often contain tokens, session IDs, or user-specific data. Log only the endpoint path and HTTP method, not the full URL with query string. For headers, either omit them entirely or only log a pre-approved list like content-type and user-agent (but be aware user-agent can sometimes be tied to a device).
  7. Use a correlation ID. Generate a unique ID for each request and include it in the log. This lets you trace an error to a specific request without storing learner data. If you need to investigate further, you can use the correlation ID to find the request in your application’s temporary in-memory context (which you can destroy after the request ends).
  8. Implement a logging wrapper. Create a function like logError(error, context) that centralizes redaction and formatting. This ensures every error log goes through the same safe path and you don’t accidentally miss a spot later.
  9. Test with dummy data. Write tests that simulate errors with fake learner data in the request body, headers, and error message. Verify that the logs contain no trace of that data.
  10. Set up log retention and access controls. Even with redaction, logs are sensitive. Restrict who can view them, and set a retention policy (e.g., 30 days) to minimize exposure.

Common Mistakes

  • Logging the entire request object. This is the most common mistake. The request object contains headers, body, and URL—all of which can hold learner data.
  • Only redacting top-level keys. Learner data often hides in nested objects or arrays. Your redaction must be recursive.
  • Forgetting about error messages. Sometimes the error message itself contains a student name or email (e.g., “User jane.doe@school.edu not found”). Sanitize the message or use a generic message.
  • Logging stack traces without inspection. Stack traces can include file paths and sometimes variable values. While rare, they can leak data. Consider truncating or filtering stack traces.
  • Using a blacklist instead of a whitelist. Blacklists are fragile—you’ll miss new fields. A whitelist of safe fields is much safer.

Tips

  • Use structured logging. Log as JSON so you can easily search and filter. This also makes it easier to apply redaction rules.
  • Add a ‘safe’ flag to logs. If you ever need to log something that might be borderline, mark it as "containsPII": false after you’ve verified it’s clean.
  • Consider using a dedicated error-tracking service. Many services have built-in scrubbing features. If you use one, still apply your own redaction as a first line of defense.
  • Document your redaction rules. Future developers need to know what’s considered sensitive and how the system works.
  • Review your logs periodically. Set a monthly check to scan logs for accidental data leaks.

Troubleshooting

I see learner data in logs despite my redaction. This means a field slipped through. Check if the data is coming from a source you didn’t sanitize—for example, an external library that logs on its own, or a console.log you forgot to remove. Add a test that specifically sends a request with a known unique string (like “LEARNER_DATA_123”) in every possible field and then search the logs for that string.

My redaction function breaks on null or non-object values. Make sure your function handles null, undefined, arrays, and primitives gracefully. Always check typeof before recursing.

I can’t correlate an error to a request without the user ID. Use a correlation ID as described. If you need more context, log a hash of the user ID (e.g., SHA-256) instead of the raw ID. This allows you to see if the same user is hitting repeated errors without exposing the actual ID.

Stack traces are too long and noisy. Limit the stack trace to the first few lines or filter out internal framework paths. Many logging libraries allow you to trim stack traces.

My logging service automatically captures request bodies. Check your logging service’s configuration. Some services have a default that captures full request details. Disable that and rely on your own structured logs.

Frequently Asked Questions

Q: Can I log the learner’s ID if it’s just a number?
A: No. A learner ID is personally identifiable information (PII) because it can be linked back to a person. Use a hash or a correlation ID instead.

Q: What if the error message itself contains the learner’s name?
A: Sanitize the message before logging. Replace the name with a placeholder like [USER_NAME]. You can also have your error-handling layer catch exceptions before they reach the logging layer and replace the message with a generic one.

Q: Is it okay to log IP addresses?
A: Generally, IP addresses are considered personal data in many jurisdictions (e.g., GDPR). Avoid logging them. If you must, truncate or hash them.

Q: How do I handle errors from third-party APIs?
A: Wrap the third-party call in a try/catch and only log the response status and a generic error code. Never log the full response body, as it might contain learner data that was sent to the third party.

Q: Should I log the request body for debugging?
A: No. The request body often contains answers, assignments, or personal info. If you need to debug, log a schema of the body (e.g., {"questionId": "number", "answer": "string"}) instead of the actual values.

Q: Can I use a logging library that automatically redacts?
A: Yes, some libraries offer redaction patterns. However, they are not foolproof. Always implement your own whitelist-based redaction as the primary method and use the library’s features as a secondary layer.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →