{"record":{"id":"9e566e7fb0e3035d","repo":"grpc/grpc-java","slug":"can-not-initialize-the-env-variable-grpc-binary-l","errorCode":null,"errorMessage":"Can not initialize. The env variable GRPC_BINARY_LOG_CONFIG must be valid.","messagePattern":"Can not initialize\\. The env variable GRPC_BINARY_LOG_CONFIG must be valid\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"services/src/main/java/io/grpc/protobuf/services/BinaryLogProviderImpl.java","lineNumber":63,"sourceCode":"  @SuppressWarnings(\"InlineMeSuggester\") // Only called internally; don't care\n  public BinaryLogProviderImpl(BinaryLogSink sink) throws IOException {\n    this(sink, System.getenv(\"GRPC_BINARY_LOG_CONFIG\"));\n  }\n\n  /**\n   * Creates an instance.\n   * @param sink ownership is transferred to this class.\n   * @param configStr config string to parse to determine logged methods and msg size limits.\n   * @throws IOException if initialization failed.\n   */\n  public BinaryLogProviderImpl(BinaryLogSink sink, String configStr) throws IOException {\n    this.sink = Preconditions.checkNotNull(sink);\n    try {\n      factory = new BinlogHelper.FactoryImpl(sink, configStr);\n    } catch (RuntimeException e) {\n      sink.close();\n      // parsing the conf string may throw if it is blank or contains errors\n      throw new IOException(\n          \"Can not initialize. The env variable GRPC_BINARY_LOG_CONFIG must be valid.\", e);\n    }\n  }\n\n  @Nullable\n  @Override\n  public ServerInterceptor getServerInterceptor(String fullMethodName) {\n    BinlogHelper helperForMethod = factory.getLog(fullMethodName);\n    if (helperForMethod == null) {\n      return null;\n    }\n    return helperForMethod.getServerInterceptor(counter.getAndIncrement());\n  }\n\n  @Nullable\n  @Override\n  public ClientInterceptor getClientInterceptor(\n      String fullMethodName, CallOptions callOptions) {","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/services/src/main/java/io/grpc/protobuf/services/BinaryLogProviderImpl.java#L45-L81","documentation":"BinaryLogProviderImpl's constructor wraps a RuntimeException from BinlogHelper.FactoryImpl (parsing the GRPC_BINARY_LOG_CONFIG string) into an IOException with this message, after closing the sink. It means the binary log configuration string is blank or syntactically invalid, so binary logging cannot be initialized.","triggerScenarios":"Constructing BinaryLogProviderImpl (e.g. via grpc-services binary log setup) where new BinlogHelper.FactoryImpl(sink, configStr) throws because configStr is blank, malformed, or contains duplicate/invalid entries.","commonSituations":"Setting the GRPC_BINARY_LOG_CONFIG env var to an empty value, a typo like 'svc{}' or 'foo{h:}' , or a string with a duplicate '*' entry when wiring up gRPC binary logging.","solutions":["Fix the GRPC_BINARY_LOG_CONFIG value to a valid pattern list, e.g. '*{h:2;m:100}' or 'my.Service/Method{h}'","Ensure the value is not blank and entries use service[/method]{options} syntax separated appropriately","Check for duplicate '*' (global) entries in the config string","Test the config string locally by running FactoryImpl parsing before deploying"],"exampleFix":"// before\nGRPC_BINARY_LOG_CONFIG=\"\"\n// after\nGRPC_BINARY_LOG_CONFIG=\"*{h:2;m:100}\"","handlingStrategy":"validation","validationCode":"String cfg = System.getenv(\"GRPC_BINARY_LOG_CONFIG\");\nif (cfg == null || cfg.trim().isEmpty()) {\n  throw new IllegalStateException(\"GRPC_BINARY_LOG_CONFIG is blank; set e.g. \\\"*{h:2;m:100}\\\"\");\n}\n// sanity: entries must be service[/method]{opts} or *{opts}\nfor (String entry : cfg.split(\",\")) {\n  if (!entry.matches(\"^(\\\\*|[A-Za-z0-9_.]+(/[A-Za-z0-9_.]+)?)\\\\{[^}]*\\\\}$\")) {\n    throw new IllegalStateException(\"Bad binlog entry: \" + entry);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  BinaryLogProviderImpl provider = new BinaryLogProviderImpl(sink, configStr);\n} catch (IOException e) {\n  logger.atWarning().withCause(e).log(\"Invalid GRPC_BINARY_LOG_CONFIG; disabling binary log\");\n}","preventionTips":["Validate the env var value in CI before deploy","Use documented syntax: comma-separated service[/method]{h;m} entries","Never leave GRPC_BINARY_LOG_CONFIG blank when binary logging is enabled"],"tags":["grpc","binary-log","configuration","env-var"],"backgroundTag":"invalid-config-value","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}