Search logs using Datadog syntax with support for message searches, tag filtering, attribute queries, and boolean operators. # Search logs using a Datadog-like syntax The Grepr platform supports searching logs using a syntax similar to Datadog's log query syntax. This support allows you to filter and search log data using familiar Datadog queries and eases migration from or integration with existing Datadog-based workflows. For the complete reference to Datadog query syntax, see [Query Syntax](https://docs.datadoghq.com/tracing/trace_explorer/query_syntax). By default, queries search the message field of log entries, but you can also query specific tags and attributes. ## Basic query structure ```sql -- Simple text search (searches message field by default) error -- Explicit message field search message:error -- Tag search service:web-app -- Attribute search @user.id:12345 ``` ## Case sensitivity rules * **Message searches** are case-insensitive. * **Tag searches** are case-insensitive. * **Attribute searches** are case-sensitive, wildcard searches included. ## Search message fields Message field queries perform full-text searches across the `message` field of log entries. These searches are case-insensitive and use word boundary matching. ### Perform full-text searches ```sql -- Search for "error" in message field (case-insensitive) error -- Explicit message field syntax message:error -- Both queries above are equivalent ``` ### Search for phrases Use double quotes to search for exact phrases: ```sql -- Search for exact phrase message:"connection timeout" -- Without quotes, this would search for logs containing both "connection" AND "timeout" message:connection timeout ``` ### Examples ```sql -- Find all error messages error -- Find specific error types message:"database connection failed" -- Find logs mentioning specific components message:authentication -- Case-insensitive matching message:ERROR -- matches "error", "Error", "ERROR", etc. ``` ## Wildcard queries Wildcard queries allow flexible pattern matching using `*` (zero or more characters) and `?` (single character). ### Asterisk wildcard (`*`) ```sql -- Contains pattern - matches any characters before/after *timeout* -- Prefix pattern - matches anything starting with "auth" auth* -- Suffix pattern - matches anything ending with "error" *error ``` ### Question mark wildcard (`?`) ```sql -- Single character wildcard f?o -- matches "foo", "fao", "f1o", etc. -- Multiple single character wildcards te?t -- matches "test", "text", "tent", etc. ``` ### Complex patterns ```sql -- Mixed wildcards *f?OO? -- matches "afOOd", "1fOOx", etc. -- Multiple asterisks *auth*service* -- matches logs containing "auth" followed by "service" ``` ### Escape wildcards You generally cannot search for special characters in the message field. If you need to search for a literal `*` or `?`, you'll need to extract the value into an attribute and then search in that attribute. ## Tag queries Tags in Grepr are key-value pairs that provide structured metadata about log entries. Tag searches are case-insensitive, so `service:Web-App` matches `web-app`. ### Search tag values ```sql -- Search for specific tag value service:web-app -- Search for tag with dotted notation service.version:1.2.3 -- Search for tag values with spaces (use quotes) environment:"staging environment" ``` ### Check tag key existence Check if a tag key exists regardless of its value: ```sql -- Check if 'service' tag exists tags:service -- Check if nested tag key exists tags:service.version ``` ### Use wildcards with tag values ```sql -- Tag values starting with "web" service:web-* -- Tag values ending with "app" service:*-app -- Tag values containing "prod" environment:*prod* ``` ### Use wildcards with tag keys ```sql -- Tag keys starting with "serv" tags:serv* -- Tag keys ending with "id" tags:*id ``` ### Examples ```sql -- Find logs from specific service service:user-authentication -- Find logs from production environment environment:production -- Find logs from any web service service:web-* -- Find logs that have a user ID tag tags:user.id -- Find logs from services in staging environment:staging AND service:* ``` ## Attribute queries Attributes are structured data fields extracted from log messages. Attribute searches are case-sensitive and use the `@` prefix. ### Basic attribute search ```sql -- Search for specific attribute value @user.id:12345 -- Search for nested attributes @request.method:GET -- Search for attributes with special characters @error.code:"AUTH_001" ``` ### Search phrase attributes ```sql -- Search for exact phrase in attribute @error.message:"database connection failed" -- Search for attribute containing spaces @user.name:"John Smith" ``` ### Use wildcards with attributes ```sql -- Attribute values starting with pattern @request.path:/api/* -- Attribute values ending with pattern @file.name:*.log -- Attribute values containing pattern @error.message:*timeout* ``` A tag or attribute wildcard matches the whole value, so in a multi-line value `*` and `?` match line breaks too. ### Query nested attributes Attributes can contain complex nested structures: ```sql -- Search in arrays @tags.environment:production -- Search in nested objects @metadata.request.user_id:12345 -- Search for string values @response.body:"success" ``` ### Examples ```sql -- Find logs from specific user @user.id:user123 -- Find HTTP errors @response.status_code:500 -- Find slow requests @request.duration:*slow* -- Find logs with specific error codes @error.code:AUTH_* -- Find logs from specific IP addresses @client.ip:192.168.* ``` ## Boolean operators Combine multiple query conditions using boolean operators. ### AND operator ```sql -- Explicit AND service:web-app AND @user.id:12345 -- Implicit AND (space-separated terms) service:web-app @user.id:12345 -- Multiple conditions error AND service:auth AND @response.status:500 ``` ### OR operator ```sql -- Search for either condition service:web-app OR service:api-gateway -- Multiple OR conditions @response.status:500 OR @response.status:502 OR @response.status:503 -- Combine with other operators (service:web OR service:api) AND error ``` ### NOT operator ```sql -- Exclude with minus sign service:web-app -@user.id:12345 ``` ### Group conditions with parentheses ```sql -- Group OR conditions (service:web-app OR service:api) AND error -- Complex grouping (error OR warning) AND (service:auth OR service:payment) -- Nested grouping ((service:web OR service:api) AND error) OR @priority:high ``` ### Must and must not operators ```sql -- Must have (equivalent to AND) +service:web-app +@user.id:12345 -- Must not have (equivalent to NOT) +service:web-app -@user.id:12345 -- Complex requirements +error +service:auth -@user.type:admin ``` ### Range queries ```sql -- Inclusive range @response.time:[100 TO 500] -- Exclusive range @response.time:{100 TO 500} -- Open-ended range @response.time:[* TO 300] @response.time:[200 TO *] -- On tags, range queries are lexicographical hostname:[jimmy TO tom] ``` ### Comparison operators ```sql -- Greater than @response.time:>300 -- Less than @response.time:<100 -- Greater than or equal to @response.time:>=200 -- Less than or equal to @response.time:<=400 -- On tags, comparisons are lexicographical hostname:>=jimmy hostname: